How to setup PYTHONPATH globally by default?
sys.path is PYTHONPATH plus the documents directory.
sys.path.append() works as documented, but does not go back and modify the PYTHONPATH environment variable.
- https://docs.python.org/3/tutorial/modules.html#standard-modules
- https://docs.python.org/3/library/sys.html#sys.path
import os
import sys
python_path = set(os.getenv("PYTHONPATH").split(":"))
system_path = set(sys.path)
print(f"{len(python_path) = } but {len(system_path) = }")
print(f"{system_path ^ python_path = }")
sys.path.append("my/special/place") # <-- this works but does not modify the `PYTHONPATH` environment variable.
python_path = set(os.getenv("PYTHONPATH").split(":"))
system_path = set(sys.path)
print(f"{len(python_path) = } but {len(system_path) = }")
print(f"{system_path ^ python_path = }")
sys.pathisPYTHONPATHplus the documents directory.
sys.path.append()works as documented, but does not go back and modify thePYTHONPATHenvironment variable.
- https://docs.python.org/3/tutorial/modules.html#standard-modules
- https://docs.python.org/3/library/sys.html#sys.path
import os import sys
python_path = set(os.getenv("PYTHONPATH").split(":")) system_path = set(sys.path)
print(f"{len(python_path) = } but {len(system_path) = }") print(f"{system_path ^ python_path = }")
sys.path.append("my/special/place") # <-- this works but does not modify the
PYTHONPATHenvironment variable.python_path = set(os.getenv("PYTHONPATH").split(":")) system_path = set(sys.path)
print(f"{len(python_path) = } but {len(system_path) = }") print(f"{system_path ^ python_path = }")
The problem it's can't be configured globally (forever) for pythonista and cause of it we have few problems with pip
- using
pip install -U --target ~/Documents/site-packageswill overwrite~/Documents/site-pachages/bin - using
pip install -U --prefix ~/Documents/site-packageswill create common tree likelib/pythonX.Y/site-packageswhich one is not in the PYTHONPATH, so we should manually move packages from~/Documents/site-packages/lib/pythonX.Y/site-packagesto~/Documents/site-packages, and in this case the onuninstallthe entry points would not be removed from~/Documents/site-pachages/bin - There no clear way to use PEP-370 in Pythonista
You can setup global modifications to sys.path in pythonista_startup.py in Pythonista 3 or using the "Startup" setting in Lab.
You can setup global modifications to sys.path in
pythonista_startup.pyin Pythonista 3 or using the "Startup" setting in Lab.
Aha, but it is not works as expected. For example StaSh can't see path changes made by pythonista_startup.py
I mean the scripts that runs via runpy can't see changes made by pythonista_startup.py