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 `
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.
import sys
sys.path.append(YOUR_PATH) # or .insert(0, YOUR_PATH) may give higher priority
or set your $PYTHONPATH
environment variable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With