python change starting up/default directory
Solution 1
Checkout: http://docs.python.org/using/cmdline.html#envvar-PYTHONSTARTUP
This is an environment variable that can be set to a file. This is executed prior to start up of shell and only applies if you are using interactive shell.
You can use this to specify a path as current directory at start of your shell.
import os
os.chdir('/pathto')
del os
Write to a file and point to it with env variable.
If this is just specific to a file that you are running, then you should be changing the directory inside the script
os.chdir('/pathto')
Solution 2
If you are trying to set up python so that it will automatically search in a specific directory on your computer when you import modules, open to your /python27/Lib/site.py file and add your paths to the PREFIXES list near the top of the file
windsound
learner of CS. Using Python, web languages, and R for now :D
Updated on June 04, 2022Comments
-
windsound about 2 years
I am new to python. Every time I start the shell, it always gives me directory as:
".../file name/Python/"
But I want to change it to:
".../file name/python program/"
How do I do it without changing the import modulate stuff? I am afraid to make it wrong so that I can't import anymore, but it is so annoy to put:
import os os.chdir(".../file name/python program/")
every time after I open the shell. Thanks for help!