1

I have two installations of Python on a corporate Windows computer. One from the Anaconda distribution:

C:\Users\Me\AppData\Local\Continuum\anaconda3\python3.exe

Another one from a corporate installer:

C:\Users\Me\AppData\Local\Downloaded Apps\WinPython\python-3.4.3\python.exe

If I type "python" in the default "cmd" terminal or in the Git Bash, it says "command not found". Probably for the same reason, Jupyter does not allow me to create a Python 3 notebook. How do I set the paths so that Python is available system-wide? I prefer the Anaconda distribution's Python.

EDIT: Creating a new user variable PYTHONPATH and setting it to C:\Users\Me\AppData\Local\Continuum\anaconda3\ via Windows System Properties does not have an effect.

clstaudt
  • 21,436
  • 45
  • 156
  • 239
  • Presumably you tried something? What didn't work? In my last job, I used `setx` to put python in the path when there was mandatory User Acount Control. That allows you to modify the path without admin rights. – roganjosh Oct 23 '17 at 13:11
  • Never had the issue before. I expected the paths to be set correctly after running the Anaconda installer. I'm also not too familiar with Windows internals. – clstaudt Oct 23 '17 at 13:13
  • 1
    Anaconda should do it by default. If you need admin rights, it will fail trying to create `envs` directory (or at least for me) and it will fail to set the path. Is that what you're facing? – roganjosh Oct 23 '17 at 13:14
  • @roganjosh Probably that's the issue. Can I still set the path manually? – clstaudt Oct 23 '17 at 13:16
  • https://stackoverflow.com/a/14649949/4799172. You don't need admin rights. Set the path to `C:\Users\Me\AppData\Local\Continuum\anaconda3\` You'll need to close the cmd (and maybe restart) before testing. – roganjosh Oct 23 '17 at 13:19
  • @roganjosh I assume you mean append `C:\Users\Me\AppData\Local\Continuum\anaconda3` to the variable "PATH". – clstaudt Oct 23 '17 at 13:21
  • Yes, I'm on my phone and struggling to format my comment but that's exactly what I typed. – roganjosh Oct 23 '17 at 13:21
  • Ok, yeah, no backticks in it :) – roganjosh Oct 23 '17 at 13:22
  • @roganjosh My issue was that "set the path" is not self-explanatory. – clstaudt Oct 23 '17 at 13:24
  • Substitute `C:\Python27` for the path you listed from the answer I linked to. – roganjosh Oct 23 '17 at 13:25
  • @roganjosh, it's better to instead use the system's per-user GUI editor under the user accounts settings. Using setx.exe is cumbersome for modifying the user's `PATH`. You first have to query the user's original value from "HKCU\Environment" using reg.exe, and take care to not expand environment variables embedded in the string. You can't simply append to `%PATH%` and set it. That will mix system and user variables, all expanded, which gets doubly concatenated with system variables when the system reloads the user's environment. setx.exe is good for simple variables like `PROMPT` and `DIRCMD`. – Eryk Sun Oct 23 '17 at 20:25

3 Answers3

0

This answer describes step-by-step an approach that worked for me. However, as eryksun notes in the comment, the additional variable should not be named PYTHONPATH. I renamed it PYTHON, which works.

Strangely, adding the paths directly to the PATH variable did NOT work.

clstaudt
  • 21,436
  • 45
  • 156
  • 239
  • 1
    Never add Python's installation directory and subdirectories (e.g. DLLs, Lib, Lib\site-packages) to the `PYTHONPATH` environment variable. That is not only *completely* pointless, but it will interfere with every other installation of Python on the system. Also, finding python.exe or py.exe is a `PATH` lookup. It has nothing to do with `PYTHONPATH`. – Eryk Sun Oct 23 '17 at 20:12
  • @eryksun What would you recommend instead? – clstaudt Oct 24 '17 at 09:15
  • @eryksun Would not using the variable name PYTHONPATH solve the problem? – clstaudt Oct 24 '17 at 10:10
  • 2
    `PYTHONPATH` adds non-standard package directories to Python's `sys.path` for module lookup. It has nothing to do with finding "anaconda3\python3.exe" or "python-3.4.3\python.exe" from a system shell or when an application calls `ShellExecuteEx` or `CreateProcess`. That's a function of the default search directories, `PATH`, and (for `ShelExecuteEx`) the system and user "App Paths" defined in the registry. Or if running a .py script directly, the shell uses the file association "open" action, for which the command-line template can be queried via `AssocQueryString`. – Eryk Sun Oct 24 '17 at 18:07
-1

You have to add the path of your installation to the Environment variables. Simply go to the System Properties / Environment Variables / From there, create a new system variables and add your python path.

pylearner
  • 537
  • 2
  • 8
  • 26
-1

In the system variable section select the Path variable. Add new variable C:\Users\Me\AppData\Local\Continuum\anaconda3\ as environment variable in your advanced System Settings. This is from where your system will invoke the python interpreter.

For more details see this answer

flamelite
  • 2,654
  • 3
  • 22
  • 42