Python Forum

Full Version: .pth file does not show up in sys.path when configuring path.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am just beginning to learn Python and I ran into a problem related to configuring path. Here is a quick background and other details:

- I have 3.6.2 running on windows
- I tried to extend the path using a simple mypath.pth txt file(Contains: C:\Users\Arjun)
- I tried saving it in the top level Python install directory(C:\...\python36-32\mypath.py)
- I also tried saving it in site-packages(C:\...\python36-32\Lib\site-packages)
- In both the cases when I try to review whether it worked(IDLE and command line) using sys.path, it does not show the contents of mypath.py(C:\Users\Arjun) in the output
- I can see current directory(''), standard modules, PYTHONPATH I configured and site-packages at last, but not the .pth file

Please help me with the issue as I am not sure where I am going wrong. I am beginner and would appreciate all the help I can get.
I find it easiest to not mess with PYTHONPATH for adding own folders permanently.
The site module offers a method that takes care of adding to sys.path without duplicates and with .pth files.
Make a sitecustomize.py file in C:\Python37\Lib\site-packages or your site-packages folder.
# sitecustomize.py
import site

site.addsitedir(r'E:\div_code')
Test that it work.
C:\
λ ptpython
>>> import sys
>>> from pprint import pprint

>>> pprint(sys.path)
['C:\\python37\\Scripts\\ptpython.exe',
 'c:\\python37\\python37.zip',
 'c:\\python37\\DLLs',
 'c:\\python37\\lib',
 'c:\\python37',
 'c:\\python37\\lib\\site-packages',
 'E:\\div_code']
For OS and Path look at Python 3.6/3.7 and pip installation under Windows
@Snippsat: Wow, this looks way more convenient and it works great. Thanks again man, as I said, I am new to Python and had no clue this module existed.