Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a default path to look for python script files in?

I've always had a bit of trouble figuring out how to get Python set up properly in Windows.

I've already set up path=%path%;C:\python27 , so I'm able to open .py files with python. I'm just having trouble figuring out how to change the save directory.

For instance, I save all of my custom scripts in the directory Documents/Python. It's Win7, so no My Documents. I would like to be able to type "HelloWorld.py" into IDLE and have it search this folder for any matching script names. I haven't been able to figure out how to add this directory to the default Python search path though.

Any ideas?

Here's one attempt.

>>> import sys 
>>> sys.path 
['C:\\Python27\\Lib\\idlelib', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages'] 
>>> sys.path.append('C:\Users\Jimmy\Documents\Python') 
>>> HelloWorld.py 
Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> HelloWorld.py NameError: name 'HelloWorld' is not defined `
like image 846
JiMeTehHak Avatar asked May 10 '11 01:05

JiMeTehHak


People also ask

What is the default file path in Python?

When we run the graphical Python Shell, the current working directory starts as the directory where the Python Shell executable is. On Windows, this depends on where we installed Python; the default directory is c:\Python32.


1 Answers

import sys
sys.path.append(YOUR_PATH)  # or .insert(0, YOUR_PATH) may give higher priority

or set your $PYTHONPATH environment variable

like image 167
ninjagecko Avatar answered Oct 12 '22 23:10

ninjagecko