Why (or why not) Add Anaconda to path?
Solution 1
PATH
is an environment variable that is a list of locations where executable programs lie (see also the wikipedia page.
Whenever you are in your command line and try to execute some program, for example regedit
, then the cmd does not magically know that you mean C:\Windows\regedit.exe
. Instead, it searches all locations in your PATH
for an executable named regedit
and finds it in C:\Windows
which is one of the standard parts of PATH
in Windows.
That is also, why messing with the PATH
can be dangerous if you don't know what you are doing, because it might lead to things not working anymore if, for example you delete parts of the path or add custom directories to it.
That being said, you should now have an idea what happens when you "Add anaconda to path". It simply means, that Anaconda adds the directory where its executables lie to the PATH, hence making it findable when, for example you type conda
in your cmd.
That being said, adding Anaconda to PATH is something that is convenient, beacuse the commands can always be found automatically and they will also be found by other programs scanning your PATH
for a python executable.
At the same time it is not neccessary. When you use e.g. pycharm, then you can specify the path to the interpreter inside of pycharm. it does not neccessarily need to be present in your PATH.
Note:
I personally have it on my PATH
because I am too lazy to open an Anaconda prompt each time I need it in a cmd
and I do not see the harm in it if you understand the consequences and its my only python installation anyway.
Also Helpful:
On windows, you can use the where
command to find out from where commands are laoded. For example:
where regedit
gives
C:\Windows\regedit.exe
This can be esspecially helpful when trying to debug PATH issues
Solution 2
The python.exe of the base environment resides in the
C:\Users\USERNAME\AppData\Local\Anaconda3 folder
If you add this folder to the PATH, you can call that version directly from the prompt and Python will also find many of the installed packages via that anchor folder. However, this is not true for e.g. the Numpy package which heavily depends on compiled C libraries. So you would also need to add the following folders to the PATH:
C:\Users\USERNAME\AppData\Local\Anaconda3\Library\mingw-w64\bin;
C:\Users\USERNAME\AppData\Local\Anaconda3\Library\usr\bin;
C:\Users\USERNAME\AppData\Local\Anaconda3\Library\bin;
C:\Users\USERNAME\AppData\Local\Anaconda3\Scripts;
C:\Users\USERNAME\AppData\Local\Anaconda3\bin;
This is exctly what the activation is for, plus it also gives you the option to easily switch between environments.
Bottom line: Adding Anaconda to the PATH might help in simple cases, but the whole concept of Anaconda's dependency management depends on environments and their activation. It's better to use Anacona the proper way right from the beginning and NOT to add Anaconda to the PATH.
Related videos on Youtube
Psychotechnopath
Updated on July 09, 2022Comments
-
Psychotechnopath almost 2 years
I have found a partial answer in this question: Adding Anaconda to Path or not
But I still don't fully understand. I have had a lot of installation issues when switching from a normal installation Python to Anaconda, requiring me to completely re-install Windows... So i want to get this right now.
What happens internally when I Add Anaconda (or python for that matter) to the PATH? I plan on working with seperate conda environments for different python versions, what could go wrong if I add Anaconda to path in the installation? And what is the difference between doing it in the installation or doing it later through the command prompt? Will it affect my ability to integrate anaconda with PyCharm?
-
FlyingTeller over 5 yearsDo you understand what "adding something to PATH" means in general?
-
Psychotechnopath over 5 yearsI have some general Idea, but not really... Could you enlighten me?
-
-
Psychotechnopath over 5 yearsThat makes complete sense. Thank you so much. I think the problem in my previous installation was that I also had regular python installed. I was able to succesfully install anaconda create new conda environments, even install packages in them but for some weird reason they would not import... I think I will not add to path then and open since, when working with conda, I open anaconda prompt anyways.
-
FlyingTeller over 5 yearsMight be. What often happens in those cases is that invoking
python
does not call the same interpreter for which the previous installation command has installed the packages. You can always check withwhere
the location of an executable and inside the python interpreter you can checkprint(sys.path)
to check where python modules are searched. Google PYTHONPATH for more information -
Psychotechnopath over 5 yearsAllright. Makes sense. This where command you mention, will it then also only work when i have python/anaconda added to path? When i try it now, on cmd.exe, in my C drive, it says: INFO: Could not find files for the given pattern(s). However, when I run it in the anaconda prompt it does return the python location. This is exactly what makes is useful to "add to path" right? Like you mention in your answer
-
FlyingTeller over 5 yearsyes exactly. What the anaconda prompt is, is a normal cmd where aanconda has beend added to the PATH so the commands can be used directly
-
Jim Raynor about 4 yearsTo make your answer even better, you can give an example/a situation of WHEN adding anaconda to PATH could mess things up.
-
Chad about 4 yearsDoes adding anaconda to the path create conflicts if one has multiple anaconda environments installed? I would have to think it would.
-
FlyingTeller about 4 years@Chad do you mean multiple anaconda installations or one installation that has multiple environments. The first setup doesn't make any sense in my opinion anyway, as it has no advantages over the second. If you have one setup with multiple environments, then adding to path does not conflict. When activating an environment the paths for the env will be prepended to the PATH variable