Python Forum
.pth file does not show up in sys.path when configuring path.
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.pth file does not show up in sys.path when configuring path.
#1
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.
Reply
#2
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
Reply
#3
@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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How does venv update $PATH without activating on Windows? bottomfeeder 3 617 Mar-13-2025, 01:46 PM
Last Post: DeaD_EyE
  Path must be screwed up somewhere BR549py 4 1,859 Sep-09-2024, 04:58 PM
Last Post: deanhystad
  os.path.exists fails with accented characters glenndrives 11 2,531 Sep-03-2024, 05:30 PM
Last Post: glenndrives
  Dictionary using path. Bobbee 5 965 Aug-22-2024, 08:43 PM
Last Post: Bobbee
  import a function from another file using relative path paul18fr 6 2,590 Aug-01-2024, 06:40 AM
Last Post: paul18fr
  Pandas ExcelWriter path name rejected morningglory 0 685 Jul-15-2024, 06:36 PM
Last Post: morningglory
  Using OpenCV and image path is invalid AudunNilsen 5 1,822 Mar-18-2024, 05:28 PM
Last Post: snippsat
  Path Planning prachibhanaria 0 776 Jan-23-2024, 10:11 AM
Last Post: prachibhanaria
  Create dual folder on different path/drive based on the date agmoraojr 2 1,271 Jan-21-2024, 10:02 AM
Last Post: snippsat
  working directory if using windows path-variable chitarup 2 1,446 Nov-28-2023, 11:36 PM
Last Post: chitarup

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020