How can I append python to path? I tried put the python root, .exe, libs folder, but nothin work. I just want run .py files at cmd in windows.
Thanks.
3 Answers 3
Control Panel, System, Advanced tab, Environment Variables (Windows XP). Edit PATH:
PATH=C:\Python26;C:\Windows;.... etc.
Comments
In Python, the PATH where the python interpreter has visibility is available from sys.path
>>>import sys
>>>print sys.path
If you want to new paths to be added that list, just append to it.
>>>sys.path.append('c:/new/path/to/lib')
1 Comment
cmd has environment variables, commands that are recognized.
To add the python command to cmd, you have to add the path to the folder in the control panel's environment variables section, which calls the python.exe file in your PC's Python folder.
To do this,
Type: environment variables in the search bar
Press the environment variables button enter image description here
- Edit PATH variable enter image description here
- Add path to PATH variable enter image description here It varies for where you installed python, but for me it is at:
C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32
To find the python.exe file
The AppData folder might be invisible. If the case, the following website is a good reference on making invisible folders visible https://www.howtogeek.com/howto/windows-vista/show-hidden-files-and-folders-in-windows-vista/
- Apply changes and open a new cmd window.
For the pip command, the same steps apply, only that the pip.exe file is in the \Scripts folder.
python path/to/file.py