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!

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.