How do I find out my python path using python?
You would probably also want this:
import sys
print(sys.path)
Or as a one liner from the terminal:
python -c "import sys; print('\n'.join(sys.path))"
Caveat: If you have multiple versions of Python installed you should use a corresponding command python2
or python3
.
sys.path
might include items that aren't specifically in your PYTHONPATH
environment variable. To query the variable directly, use:
import os
try:
user_paths = os.environ['PYTHONPATH'].split(os.pathsep)
except KeyError:
user_paths = []
Can't seem to edit the other answer. Has a minor error in that it is Windows-only. The more generic solution is to use os.sep as below:
sys.path might include items that aren't specifically in your PYTHONPATH environment variable. To query the variable directly, use:
import os
os.environ['PYTHONPATH'].split(os.pathsep)