Reputation: 7691
I am using the GUI method (rather than setx) to set a directory in the %PATH% environment variable on windows 7. My aim is to enable all my python scripts, modules and classes that I place in my 'D:\MPhil\Python\My_Python_Modules' directory to be available to use in the command line or another python script, but from any directory (much like the native python modules can be called from anywhere).
I have been through the process of: 'Edit the system environment variables->Environment variables->add my directory to the start of the %PATH% variable'
such that it now looks like this
'D:\MPhil\Python\My_Python_Modules\;C:\Program Files (x86)\ActiveState Komodo IDE 8\;...'
However, the 'Identify_Gene.py' script contained within the directory is still not callable (using the command 'python Identify_Gene.py', from a random directory.
Does anybody know what I am doing wrong?
Upvotes: 0
Views: 417
Reputation: 149155
You are making a confusion between the PATH
environment variable, which is where the shell (cmd.exe
) searches for commands and the PYTHONPATH
environment variable which initializes the sys.path
variable that Python uses to find modules.
You can try 2 ways of doing (more or less) what you want :
.py
and .pyw
files must be executed through the Python
interpreter. You can prepend the directory where you put your script to the PATH
(like you did) and call your script directly (and not python Identify_Gene.py
) Identify_Gene.py
PATH
and put the directory containing your scripts into PYTHONPATH
(you can create new environment variables under Windows if it does not exists). You can the call your scripts as modules : python -m Identify_Gene
Upvotes: 1
Reputation: 6270
You can do the following:
Add to Windows environment varibale PATHEXT
python script extension:.PY
set PATHEXT=%PATHEXT%;.PY
(use Env. Settings GUI to make it permament)
In command line: register that python extension:
assoc .py=Python.File
In command line: add application invoker to the extension:
ftype Python.File=<path to python exe>\pythonw.exe "%%1" %%*
Next time you could simply run your script by name in the command line and without .py
extension (if you set your PATH
variable).
Another option: you should add path of your scripts folder to the PYTHONPATH
variable and then you could invoke your scripts in the form:
python -m <script name>
Upvotes: 1