2

In the following structure:

- foobar
  - __init__.py
  - pyfoo
    - __init__.py
    - foo.pyd
    - src
      - __init__.py
      - test
        - __init__.py
        - bar.py

I try to load foo.pyd from bar.py. Therefor I inserted an entry into PYTHONPATH with \\?\C:\<path_to_foobar>\foobar\pyfoo.

In bar.py I then try to

import foo

, which never finds foo.

Now when I look at sys.path, entries from PYTHONPATH are missing. Also, when I look under which paths foo.pyd is searched, only paths of sys.path are taken into account.

So how come sys.path does not contain all paths of PYTHONPATH?


EDIT:

To test the paths I inserted logs right before import:

print("SP %s" % sys.path)
print("PP %s" % os.environ["PYTHONPATH"])

Which gives me something like:

SP ['\\\\?\\B:\\foobar\\pyfoo\\src\\test', 'C:\\python3\\win_x86_64\\python35.zip', 'C:\\python3\\win_x86_64\\DLLs', 'C:\\python3\\win_x86_64\\lib', 'C:\\python3\\win_x86_64']
PP \\?\B:\;\\?\B:\foobar\pyfoo;\\?\B:\foobar;\\?\B:\foobar\pyfoo
14
  • how did you insert your PYTHONPATH entry? are you sure that the variable is defined where you're running your script? you may echo PYTHONPATH before starting your script. Clearly a minimal reproducible example is missing here. Commented Feb 8, 2017 at 13:14
  • See Edit, I am not only echoing before but in the Script. Commented Feb 8, 2017 at 13:23
  • I understand you replaced your server name by ?. If not there's a first problem: this cannot be a valid path. And the other error is the drive : which should be $ in the case of UNC paths with drives. Your UNC paths doesn't seem valid. Commented Feb 8, 2017 at 13:35
  • 1
    `\\?` is a long-path prefix on Windows. Read: msdn.microsoft.com/en-us/library/windows/desktop/… Commented Feb 8, 2017 at 13:56
  • Ok, so it's valid windows-wise. do you really need that? can you try without? Commented Feb 8, 2017 at 14:00

2 Answers 2

1

Cannot reproduce your problem, with my Windows 7-x64 + python 3.4.4-x64 version it works, contents of PYTHONPATH are present in sys.path:

set PYTHONPATH=\\?\L:\SO
python

>>> import sys
>>> sys.path
['', '\\\\?\\L:\\SO', ... , 'D:\\Python34-x64\\lib\\site-packages']

That said, as a workaround, you could force the contents of PYTHONPATH into sys.path like this:

import os,sys
sys.path.extend(os.getenv("PYTHONPATH").split(os.pathsep))

# now you can import foo
import foo
Sign up to request clarification or add additional context in comments.

9 Comments

Can you try to call a script with prefixed path please?
What version of Windows are you using?
Windows 7 64-bit. What version of python are you using?
Python3.6 on Windows 10.
Python 3.6 is still new. You may be on to something here. Could you try with an older version by your end? (note: I edited the tags of your question to reflect python 3.6)
|
0

Trying (with 3.5.2-embeddable):

set PYTHONPATH=\\?\C:\Windows

C:\python3.5.2\win_x86_64\python.exe \\?\C:\temp\test.py

with test.py:

import os
import sys

print("SP %s" % sys.path)
print("PP %s" % os.environ["PYTHONPATH"])

Leads to \\?\C:\Windows being missing from sys.path.

Making the same test with set PYTHONPATH=C:\Windows works like a charm in 3.5.2-embeddable.

The same test with 3.6.0-embeddable does not add to sys.path in any case.

And 3.6.0-embeddable seems like the intended behavior https://bugs.python.org/issue28245

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.