Hey guys!

I'm having a hard time finding a way to set up pythonpath on a windows machine, by a script. I know how to do it manually, but I want to make a script that would add a certain directory to pythonpath and would save it. Thanks for reading, help is appreciated!

Recommended Answers

import sys

sys.path.append('/path/to/directory')

Jump to Post

Windows note: control panel>System>Advanced>Environment Variable
allows you to add PYTHONPATH + directories used

Jump to Post

All 6 Replies

import sys

sys.path.append('/path/to/directory')

Windows note: control panel>System>Advanced>Environment Variable
allows you to add PYTHONPATH + directories used

You can also add within the program that needs it:

# add these lines to the beginning of your program
import sys
# for instance add myfolder123 folder to PYTHONPATH
sys.path.append(r'C:\Python27\Lib\site-packages\myfolder123')

Did you guys read my post? I specifically asked for a .py or .bat script that would set it up permanently so I wouldn't have to put a sys.path.append in every file.

Okay rude&crude use the Windows Environment Variable

You can call the setx command from python using subprocess.Popen.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.