Search code examples
pythoneclipsepydevpythonpathwine

Pydev wine pythonpath issues/console initialization timeout issue


I've set up an interpreter in Pydev that calls a small script:

#!/bin/bash
WINEDEBUG=fixme-all WINEPREFIX=/home/dal/wine/Python wine C:\\Python27\\python.exe "$@"

to fire up an instance of the windows version of python (which I need in order to get to windows-only ODBC database drivers). This much works fine, I am able to start a console, run scripts using that interpreter etc.

However - I now need to add a reference to a directory storing a bunch of modules that I need to access - however the windows version of python wants a PYTHONPATH that has elements separated by semicolons and in Z:\home\blah\whatever format, rather that colons and /home/blah/whatever.

Pydev won't let me add arbitrary paths in the preferences -> pydev -> interpreters -> libraries section (it wants me to find the path in a file picker, then creates a /home/blah/whatever string from what was picked).

Attempting to use the enviroment tab to set PYTHONPATH to ${PYTHONPATH}\;Z:\path\I\need results in pydev telling me to forget about it (it won't let me set PYTHONPATH specifically from that dialog).

Adding PYTHONPATH=${PYTHONPATH}\;Z:\\path\\I\\need to the shell script which calls the windows version of python via wine was the last thing I could think of, but it causes something bad to happen in pydev:

Error initializing console.
Unexpected error connecting to console.
Failed to recive suitable Hello response from pydevconsole. Last msg  received: Failed to read server's response: Connection refused

yup, it fails to recive.

I can manually:

import sys
sys.path.append(r'Z:\really\long\path\that\I\dont\want\to\type\often')

and things will work, but...I'd really like to not have to type that each time.

putting the above in a file and pointing the PYTHONSTARTUP environmental variable at it solves that problem for a python instance running from the terminal, but the python instance running inside pydev doesn't seem to look at PYTHONSTARTUP at all

Gone through just about all the ideas I can come up with at this time of night (short of simply importing the whole modules directory into every project I work on in pydev, which seems...inelegant, to say the least), does anyone else have a thought on how to push this particular square peg through the round hole?

Update: the module directory is actually mounted via sshfs, and with it in the pythonpath, launching an instance of the python interpreter from a terminal is somewhat slow (35sec ish). Attempting to launch a console from within pydev appears to time out in < 15sec, so I'm wondering if what's needed here is just some way to increase the amount of time it waits for a response from the interpreter it's trying to launch before giving up, and if the 'connection refused' message at the end of the output snippet means (as the rest of that snippet seems to suggest) 'connection not accepted before I gave up' more so than 'interpreter told me explicitly connection was not going to happen'?


Solution

  • I would try playing around with sys.path

    import sys
    print sys.path #  print a list of locations Python searches for modules
    sys.path.append('Z:\\path\\I\\need')
    
    # now import your modules
    import my_module
    

    Regarding your PYTHONPATH method, you could also try putting into single quotes - your current method doesn't escape properly, and \\n is interpreted as a newline character.

    PYTHONPATH=${PYTHONPATH}\;'Z:\\path\\I\\need'