I have a directory which hosts all of my Django apps (
C:My_Projects
). I want to add this directory to my PYTHONPATH
so I can call the apps directly.I tried adding
C:My_Projects;
to my Windows Path
variable from the Windows GUI (My Computer > Properties > Advanced System Settings > Environment Variables
). But it still doesn't read the coltrane module and generates this error:How python finds its modules. Strictly taken, a module is a single python file, while a package is a folder containing python files, accompanied by a (can be empty) file named init.py, to tell python it is a package to import modules from. So I'm trying python 2.7 on my Windows. It is running Windows 8. I cannot add it to my path. I've done the usual: using the advanced system settings, environment variables, adding C: Python27 in system variables. However, when I type Python in command prompt it says 'python is not recognized.'
Error: No module named coltrane
darrendarren
18 Answers
You know what has worked for me really well on windows.
My Computer > Properties > Advanced System Settings > Environment Variables >
Just add the path as C:Python27 (or wherever you installed python)
OR
Then under system variables I create a new Variable called
PythonPath
. In this variable I have C:Python27Lib;C:Python27DLLs;C:Python27Liblib-tk;C:other-folders-on-the-path
This is the best way that has worked for me which I hadn't found in any of the docs offered.
EDIT: For those who are not able to get it,Please add
C:Python27;
along with it. Else it will never work.
darrendarren
Windows 7 ProfessionalI Modified @mongoose_za's answer to make it easier to change the python version:
- [Right Click]Computer > Properties >Advanced System Settings > Environment Variables
- Click [New] under 'System Variable'
- Variable Name: PY_HOME, Variable Value:C:pathtopythonversion
- Click [OK]
- Locate the 'Path' System variable and click [Edit]
- Add the following to the existing variable:%PY_HOME%;%PY_HOME%Lib;%PY_HOME%DLLs;%PY_HOME%Liblib-tk;
- Click [OK] to close all of the windows.
As a final sanity check open a command prompt and enter python. You should see
If you need to switch between versions, you only need to modify the PY_HOME variable to point to the proper directory. This is bit easier to manage if you need multiple python versions installed.
Delicia BrummittDelicia Brummitt
Just append your installation path (ex. C:Python27) to the PATH variable in System variables. Then close and open your command line and type 'python'.
Paulino IIIPaulino III
From Windows command line:
To set the PYTHONPATH permanently, add the line to your
autoexec.bat
. Alternatively, if you edit the system variable through the System Properties, it will also be changed permanently.Yuval AdamYuval Adam
These solutions work, but they work for your code ONLY on your machine. I would add a couple of lines to your code that look like this:
That should take care of your problems
inspectorG4dgetinspectorG4dget
Adding Python and PythonPath to the Windows environment:
- Open Explorer.
- Right-click 'Computer' in the Navigation Tree Panel on the left.
- Select 'Properties' at the bottom of the Context Menu.
- Select 'Advanced system settings'
- Click 'Environment Variables...' in the Advanced Tab
- Under 'System Variables':
- Add
PY_HOME
PYTHONPATH
- Append
path
Mr. PolywhirlMr. Polywhirl
The easier way to set the path in python is : click start> My Computer >Properties > Advanced System Settings > Environment Variables >second windows >
select Path > Edit > and then add ';C:Python27;C:Python27Scripts'
link :http://docs.python-guide.org/en/latest/starting/install/win/
Bamara CoulibalyBamara Coulibaly
You need to add to your PYTHONPATH variable instead of Windows PATH variable.
TaoTao
You can also add a
.pth
file containing the desired directory in either your c:PythonX.X
folder, or your site-packages folder
, which tends to be my preferred method when I'm developing a Python package.See here for more information.
brentlancebrentlance
This won't persist over reboots or get translated to other files. It is however great if you don't want to make a permanent modification to your system.
Gajendra D AmbiGajendra D Ambi
In Python 3.4 on windows it worked when I added it to PATH enviroment variable instead of PYTHONPATH. Like if you have installed Python 3.4 in D:ProgrammingPython34 then add this at the end of your PATH environment variable
Close and reopen command prompt and execute 'python'. It will open the python shell. This also fixed my Sublime 3 issue of 'python is not recognized as an internal or external command'.
OctaneOctane
The python 2.X paths can be set from few of the above instructions.Python 3 by default will be installed in C:UsersAppDataLocalProgramsPythonPython35-32So this path has to be added to Path variable in windows environment.
Pavan EbbadiPavan Ebbadi
To augment PYTHONPATH, run regedit and navigate to KEY_LOCAL_MACHINESOFTWAREPythonPythonCore and then select the folder for the pythonversion you wish to use. Inside this is a folder labelled PythonPath,with one entry that specifies the paths where the default installstores modules. Right-click on PythonPath and choose to create a newkey. You may want to name the key after the project whose modulelocations it will specify; this way, you can easily compartmentalizeand track your path modifications.
thanks
Brajendu Kumar DasBrajendu Kumar Das
The easiest way to do that successfully, is to run the python installer again (after the first installation) and then:
- choose Modify.
- check the optional features which you want and click Next.
- here we go, in 'Advanced Options' step you must see an option saying 'Add Python to environment variables'. Just check that option and click Install.When the installation is completed, python environment variables are added and you can easily use python everywhere.
Hamidreza AhmadiHamidreza Ahmadi
For anyone trying to achieve this with Python 3.3+, the Windows installer now includes an option to add python.exe to the system search path. Read more in the docs.
Andreas BergströmAndreas Bergström
This
PYTHONPATH
variable needs to be set for ArcPY
when ArcGIS Desktop is installed. PYTHONPATH=C:arcgisbin
(your ArcGIS home bin)For some reason it never was set when I used the installer on a Windows 7 32-bit system.
Dan RandolphDan Randolph
Maybe a little late, but this is how you add the path to the Windows Environment Variables.
- Go to the Environment Variables tab, you do this by pressing Windows key + Pausa inter.
- Go to Advanced System Settings.
- Click on Environment Variables.
- On the lower window search for the 'Path' value.
- Select it
- Click on Edit
- In the end of the line add your instalation folder and the route to 'Scripts' folder.
- Click ok, aceptar etc.
You're done, enter cmd and write python from any location of your drive, it should enter the Python program.
Example with my pc (I have
Python34
)Hope it helps.
Greetings from Bogotá
sandatomosandatomo
You can set the path variable for easily by command prompt.
- Open run and write cmd
- In the command window write the following:set path=%path%;C:python36
- press enter.
- to check write python and enter. You will see the python version as shown in the picture.
Abdur RahmanAbdur Rahman
protected by Community♦Dec 29 '15 at 15:25
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?