0

I have some modules in one directory path that I want to import into the python shell while in another path. I set the PYTHONPATH variable in the shell

c:\Users\me\Documents> set PYTHONPATH="C:\Users\me\Documents\sandbox\puzzler3\build\lib"
c:\Users\me\Documents> set | grep PYTHONPATH
PYTHONPATH="C:\Users\me\Documents\sandbox\puzzler3\build\lib"

From the default directory \Users\me\Documents\poly, I do the following

poly> python
>>> import sys
sys.path

Instead of seeing the PYTHONPATH path in the list, I see a mangled concatenation of the current default path with PYTHONPATH. Changing to a different default directory gives the same results but with the new directory path.

'c:\\Users\\me\\Documents\\poly\\"C:\\Users\\me\\Documents\\sandbox\\puzzler3\\build\\lib"'

Naturally, trying to import modules from the desired location fails. Unsetting PYTHONPATH, restarting python, and printing out sys.path shows a list without the current default directory.

Why is python performing this concatenation instead of simply including the contents of PYTHONPATH as an element is sys.path?

asked May 23, 2018 at 15:27

2 Answers 2

0

Remove the quotes.

set PYTHONPATH=C:\Users\me\Documents\sandbox\puzzler3\build\lib

It seems that the string within quotes is interpreted as a relative path (a filename perhaps?), so it concatenates it to the CWD.

answered May 23, 2018 at 15:31
Sign up to request clarification or add additional context in comments.

Comments

0

If you are already having PYTHONPATH set and want to add your library as well to the path do. (Note. With out quotes)

set PYTHONPATH=%PYTHONPATH%;C:\Users\me\Documents\sandbox\puzzler3\build\lib
answered May 23, 2018 at 15:33

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.