Меню

Adding python path windows 10

How do I add Python to the Windows PATH?

I want to be able to run Python commands from the Windows CMD. However, if I don’t specify Python’s full path for each command, I get an error saying «Python is not recognized as an internal or external command, operable program or batch file.«

How do I add Python to the Windows PATH permanently?

5 Answers 5

For Windows 10/8/7:

  1. Open System Properties (Right click Computer in the start menu, or use the keyboard shortcut Win + Pause )
  2. Click Advanced system settings in the sidebar.
  3. Click Environment Variables.
  4. Select PATH in the System variables section
  5. Click Edit

Add Python’s path to the end of the list (the paths are separated by semicolons). For example:

For Windows XP:

  1. Open System Properties (Type it in the start menu, or use the keyboard shortcut Win + Pause )
  2. Switch to the Advanced tab
  3. Click Environment Variables.
  4. Select PATH in the System variables section
  5. Click Edit

Add Python’s path to the end of the list (the paths are separated by semicolons). For example:

Test on a new terminal window or if using an integrated terminal within a text editor, close and restart your editor or the changes won’t be applied.

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.

  • Click on the windows button to start a search
  • type in «system env» and click on the «edit system environment variables»
  • Now click on the advanced tab on the top
  • At the bottom click the button that says «environment variables»
  • Now on the «user variables’your user name'» box at the top of the windows click on path then edit
  • This should lead to another window where you want to click «new» and type in the commands: «C:\Python27» and «C:\Python27\scripts»
  • Python should now work on command prompt

Windows has a built-in dialog for changing environment variables (following guide applies to XP classical view): Right-click the icon for your machine (usually located on your Desktop and called “My Computer”) and choose Properties there. Then, open the Advanced tab and click the Environment Variables button.

Источник статьи: http://superuser.com/questions/143119/how-do-i-add-python-to-the-windows-path

How to add to the PYTHONPATH in Windows, so it finds my modules/packages?

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:

Error: No module named coltrane

22 Answers 22

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)

Then under system variables I create a new Variable called PythonPath . In this variable I have C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-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

along with it. Else it will never work.

Windows 7 Professional I Modified @mongoose_za’s answer to make it easier to change the python version:

  1. [Right Click]Computer > Properties >Advanced System Settings > Environment Variables
  2. Click [New] under «System Variable»
  3. Variable Name: PY_HOME, Variable Value:C:\path\to\python\version
  4. Click [OK]
  5. 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%\Lib\lib-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.

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.

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’.

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

Adding Python and PythonPath to the Windows environment:

  1. Open Explorer.
  2. Right-click ‘Computer’ in the Navigation Tree Panel on the left.
  3. Select ‘Properties’ at the bottom of the Context Menu.
  4. Select ‘Advanced system settings’
  5. Click ‘Environment Variables. ‘ in the Advanced Tab

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:\Python27\Scripts\»

You need to add to your PYTHONPATH variable instead of Windows PATH variable.

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.

The easiest way to do that successfully, is to run the python installer again (after the first installation) and then:

  1. choose Modify.
  2. check the optional features which you want and click Next.
  3. 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.

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.

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:\Programming\Python34 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’.

The python 2.X paths can be set from few of the above instructions. Python 3 by default will be installed in C:\Users\\AppData\Local\Programs\Python\Python35-32\ So this path has to be added to Path variable in windows environment.

To augment PYTHONPATH, run regedit and navigate to KEY_LOCAL_MACHINE \SOFTWARE\Python\PythonCore and then select the folder for the python version you wish to use. Inside this is a folder labelled PythonPath, with one entry that specifies the paths where the default install stores modules. Right-click on PythonPath and choose to create a new key. You may want to name the key after the project whose module locations it will specify; this way, you can easily compartmentalize and track your path modifications.

The PYTHONPATH environment variable is used by Python to specify a list of directories that modules can be imported from on Windows. When running, you can inspect the sys.path variable to see which directories will be searched when you import something.

To set this variable from the Command Prompt, use: set PYTHONPATH=list;of;paths .

To set this variable from PowerShell, use: $env:PYTHONPATH=’list;of;paths’ just before you launch Python.

Setting this variable globally through the Environment Variables settings is not recommended, as it may be used by any version of Python instead of the one that you intend to use. Read more in the Python on Windows FAQ docs.

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.

This question needs a proper answer:

Just use the standard package site , which was made for this job!

and here is how (plagiating my own answer to my own question on the very same topic):

  1. Open a Python prompt and type
  1. Create this folder if it does not exist yet:
  1. Create a file sitecustomize.py in this folder containing the content of FIND_MY_PACKAGES , either manually or using something like the following code. Of course, you have to change C:\My_Projects to the correct path to your custom import location.

And the next time you start Python, C:\My_Projects is present in your sys.path , without having to touch system-wide settings. Bonus: the above steps work on Linux, too!

This PYTHONPATH variable needs to be set for ArcPY when ArcGIS Desktop is installed.

PYTHONPATH=C:\arcgis\bin (your ArcGIS home bin)

For some reason it never was set when I used the installer on a Windows 7 32-bit system.

I got it worked in Windows 10 by following below steps.

Under environment variables, you should only add it under PATH of «System Variables» and not under «User Variables«. This is a great confusion and eats time if we miss it.

Also, just try to navigate to the path where you got Python installed in your machine and add it to PATH. This just works and no need to add any other thing in my case.I added just below path and it worked.

Most important, close command prompt, re-open and then re-try typing «python» to see the version details. You need to restart command prompt to see the version after setting up the path in environment variables.

After restarting, you should be able to see the python prompt and below info when typing python in command prompt:

Источник статьи: http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-so-it-finds-my-modules-packages


Adblock
detector