Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
About the PYTHONPATH envvar
-
Normally the
PYTHONPATH
environment variable can be used to add additional directories in front of the default import path. By default it is empty or not set, and the default import path is always added after any locations fromPYTHONPATH
. On Pythonista,PYTHONPATH
contains all locations from the default import path, as if there were no default import locations and all locations were user-defined. It should really be emtpy, because allsys.path
entries are provided by default, and none of them are set by the user.Why does this matter?
setuptools
does some magic by installing a customsite.py
undersite-packages
, which needs to find the realsite.py
module from the stdlib to work correctly. During this search it ignores any import locations fromPYTHONPATH
, which includes all import locations on Pythonista, meaning that nothing is searched at all and the import ofsite
fails. -
On a slightly related note, it looks like
sys.path
is reset every time a script is run (even an editor action) without reloadingsite
again, which means that any previoussys.path
changes fromsite
(including.pth
files) are lost untilsite
is manually reloaded.