How do I write a .pth file?

2

I want to change the directories in which Python looks for my packages and modules, and changing PYTHONPATH in Windows 10 Environment Variables does not work. So the only solution left (apparently) is to place a .pth file in my package folder.

How do I create a .pth file ? How can I write in it, how can I open it ?

Also, what should I write in it in order for Python to find it and to be able to import my package ?

Iska

Posted 2018-06-14T13:44:37.400

Reputation: 23

Answers

0

The question is old I guess, adding this answer if someone lands here! For windows 10 users, execute the following code using python. Every time you change the path_to_add variable and execute this code, a new path will be appended to the custom_path.pth file.

# site_packages_path is the packages folder, which in my case is: 
site_packages_path = r'C:\Users\Dhwani\AppData\Local\Continuum\anaconda3\Lib\site- 
packages'

# path that you wanna add, which again in my case is 
path_to_add = "C:\Users\P077172\Documents\Jupyter"

f = open(site_packages_path + "\custom_path.pth", "a")
f.write(path_to_add)

Dhwani

Posted 2018-06-14T13:44:37.400

Reputation: 16