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
  Using OpenCV and image path is invalid AudunNilsen 5 461 Mar-18-2024, 05:28 PM
Last Post: snippsat
  Path Planning prachibhanaria 0 269 Jan-23-2024, 10:11 AM
Last Post: prachibhanaria
  Create dual folder on different path/drive based on the date agmoraojr 2 378 Jan-21-2024, 10:02 AM
Last Post: snippsat
  working directory if using windows path-variable chitarup 2 682 Nov-28-2023, 11:36 PM
Last Post: chitarup
  Can't Find Path hatflyer 8 950 Oct-30-2023, 06:17 AM
Last Post: Gribouillis
  os.path.join() 'NoneType' confusion gowb0w 11 1,425 Sep-22-2023, 11:13 PM
Last Post: deanhystad
  Why wont this path work one way, but will the other way? cubangt 2 623 Sep-01-2023, 04:14 PM
Last Post: cubangt
Bug tkinter.TclError: bad window path name "!button" V1ber 2 725 Aug-14-2023, 02:46 PM
Last Post: V1ber
  Boustrophedon path planning proteca 0 610 Jun-24-2023, 02:45 PM
Last Post: proteca
  does not save in other path than opened files before icode 3 833 Jun-23-2023, 07:25 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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