Why (or why not) Add Anaconda to path? - python

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?

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, because 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 necessary. When you use e.g. pycharm, then you can specify the path to the interpreter inside of pycharm. it does not necessarily 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 loaded. For example:
where regedit
gives
C:\Windows\regedit.exe
This can be especially helpful when trying to debug PATH issues

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

Migrating from PyCharm to VS Code: setting paths

I want to switch over to VS Code. I did the following to enable python with the packages I typically use, including a local utilities package on this machine:
Searched for the setting python.pythonPath and made it PycharmProjects/Project/venv/Scripts/python.exe for both this workspace and for my user
Changed my Windows user PYTHONPATH to PycharmProjects/Project/venv/Scripts/python.exe
Tried PycharmProjects/python.exe;local-utilities-directory
However, the folder I'm trying to manually set won't show up as a possible option when I click on my interpreter in the bottom right. Instead I'm defaulting to an older interpreter that doesn't have all the packages I've amassed.
While I can access some packages, while trying to pull in my personal utilities library, pip fails (the term pip is not recognized...)
I see that there are a few other ways to change the python path, however, to my understanding, whether you do it in a .json or via the IDE UI, shouldn't actually matter.
Any help would be appreciated.
So, I think I messed things up by offering too many paths.
I had to double check that the exact same path showed up first in:
Work setting pythonPath
User setting pythonPath
Windows profile path
Windows profile PYTHONPATH
I deleted the other "backup" paths, and it ended up working.

Python conflicts when importing?

I have windows 10 with 2 user accounts, one is an old one that has Python installed. My latest account also has Python installed. I used pip install tweepy, and it now exists in the site packages. If I open my Python shell (v3.6.5), it imports fine. However, I can't get this to work when switching to Python in cmd. In here, after typing python, it says Python 3.6.6. Obviously they are different, yet they seem to be originating from the same directory.
Any ideas?
[edit] I have just realised that I have an external application that runs on Python 3.6.6., so I guess it's defaulting because of that. However, I can't uninstall that since I need it - is there a way to specify which version of Python is launched when I type python into the cmd?
[edit2]: This is the issue, and the solution there works. However, I want to be able to just type python into cmd, rather than the entire path. Since both exist in the path (and I don't want to remove the other 3.6.6.), is there a way to achieve this?
Have you thought about using a virtual environment?
https://virtualenv.pypa.io/en/latest/
When you enter "python" into your cmd it searched python.exe in the directories listed on your PATH variable.
All you need to do is to modify your PATH and add the directory path in which the python with the desired version is located.

PIP 10.0.1 - Warning "Consider adding this directory to PATH or..."

The script flake8.exe is installed in 'c:\users\me\appdata\local\programs\python\python36-32\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Did some research on this and it seems like some sort of recurring issue.
One fix recommends removing trailing slashes from the environment variable.
Any other ideas?
This occurs every time I install via PIP
I am running python 3.6
If removing trailing slashes from the environment variables don't work, please try the following.
It works fine for me.
I am using window 10 and python3.7.0
Advanced system settings -> Environment Variables -> Path
Select Edit
Select Move Up button for both python and Scripts directory.
Finally your path will be as the following.
If you are using other window version(In the case of not having move up
button), put your python and Scripts directory at the beginning of
the path.
I had the same problem and I found out it was because of installing Python from Microsoft Store, so Uninstall it and download the latest version from python.org
Also, there is an (Add Python to PATH) check box on the installer!
After defining the Path variable, make sure to restart your PC
I wasted a lot of time
Removing trailing back slashes from those path elements is a good idea.
There may also be a problem that pip is written in python which uses case sensitive compares by default, (as is the default on every commonly used platform that I am aware of other than windows). You should also make sure that your path variable matches the case expected by pip, (the actual case of the path elements on windows does not have to match).
To do this go into the control panel, system settings, advanced poperties, advanced, Environmental Variables and edit the path elements that are giving the problem. (Windows has a nasty habit of capitalizing things even when you don't).
Adding a new path solved my problem with this error:
'psycho_django' is not recognized as an internal or external command, operable program or batch file.
Yes, giving full permissions to the "C:\Program Files\Python38-32" all users location was the way to keep it from putting PIP into the Windows User folder AppData\Roaming where it decided to create a new Python\Python38-32 folder since it had no permissions to the main folder.
I fixed this on Windows by adding full control permission to the folder where I installed python.
I installed it in "C:\Program Files\Python38-32".

Running Python from Virtual environment?

Created virtual environment in ~/python/venv/venv_python2 folder.
I can run python in a regular way (for venvs):
source ~/python/venv/venv_python2/bin/activate
python
or I can run python with:
~/python/venv/venv_python2/bin/python
What is a difference between 2 above?
There is no difference.
You can check where python is running from by typing which python in bash. You'll see that it points to your virtual env when you're in it.
The purpose of the virtual environment is to isolate the dependencies inside it so you don't have to worry about knowing the precise path to the correct Python interpreter or the libraries you have installed. So while using the absolute path is technically not incorrect, it completely bypasses the facilities of the virtualenv, and could eventually end up pointing to the wrong location if you hardcode it in a script today, and decide to move, migrate, or refactor your virtualenv tomorrow.
There is a very slight, almost irrelevant difference between the two:
~/python/venv/venv_python2/bin/python specifies exactly which Python interpreter you want to use.
python runs which ever interpreter is found first when examining your path.
One of the things that source ~/python/venv/venv_python2/bin/activate does is that it puts ~/python/venv/venv_python2/bin at the front of your path, so that when you run /-free command, the first place the shell looks is that directory, meaning python will resolve to the one in your virtual environment.
So, the only way your two ways would differ is if something else modified your PATH in the meantime.

How can I make cygwin aware of enthought python?

I need scipy on cygwin, so I figured the quickest way to make it work would have been installing enthought python. However, I then realized I have to make cygwin aware of enthought before I can use it, e.g. so that calling Python from the cygwin shell I get the enthought python (with scipy) rather than the cygwin one.
How do I do that?
I can guess my question is easy, but I'm just learning about all of this and so please be patient :-)
Think about uninstalling the cygwin version of Python, at least to start with. It's easy enough to reinstall later.
Copy your Windows path.
Install the Windows version of Enthought Python.
Examine the new Windows path. The new entries probably have to be transferred to your bash shell in cygwin. (I haven't seen Enthought. There might be more than one new path entry.) But test without changing the bash path, just to be sure.
Add the new path entries to, umm, .bashrc, I think. The path under cygwin will be a colon delimited string. You'll need to use the /cygdrive path; expect to use an entry like this to put Entought in the path.
/cygdrive/c/Program Files/Enthought
To actually do that, edit .bashrc, and put these two lines (or something like them) at the end.
PATH=$PATH:/cygdrive/c/Program\ Files/Enthought
export PATH
Note that the backslash allows proper interpretation of spaces in file paths. The export statement guarantees that programs called by bash will also include that path.
Just put the directory with enthought python before the directory with Cygwin's python in your path. If both are in the same directory, use ln to create a symbolic link, store it in another directory, and place it higher in your path. The previous answer has instructions to add it to your path.

Categories

Resources