conda 4.2.13 MacOSX 10.12.1
I am trying to install packages from pip
to a fresh environment (virtual) created using anaconda. In the Anaconda docs it says this is perfectly fine. It is done the same way as for virtualenv.
Activate the environment where you want to put the program, then pip install a program...
I created an empty environment in Ananconda like this:
conda create -n shrink_venv
Activate it:
source activate shrink_venv
I then can see in the terminal that I am working in my env (shrink_venv)
. Problem is coming up, when I try to install a package using pip
:
(shrink_venv): pip install Pillow
Requirement already satisfied (use --upgrade to upgrade): Pillow in /Library/Python/2.7/site-packages
So I can see it thinks the requirement is satisfied from the system-wide package. So it seems the environment is not working correctly, definitely not like it said in the docs. Am I doing something wrong here?
Just a note, I know you can use conda install
for the packages, but I have had an issue with Pillow from anaconda, so I wanted to get it from pip
, and since the docs say that is fine.
Output of which -a pip
:
/usr/local/bin/pip
/Users/my_user/anaconda/bin/pip
** UPDATE **
I see this is pretty common issue. What I have found is that the conda env doesn't play well with the PYTHONPATH. The system seems to always look in the PYTHONPATH locations even when you're using a conda environment. Now, I always run unset PYTHONPATH
when using a conda environment, and it works much better. I'm on a mac.
If you didn't add pip when creating conda environment
and also didn't install pip inside the environment
then the only pip you got is the system pip, which will install packages globally.
Bus as you can see in this issue, even if you did either of the procedure mentioned above, the behavior of pip inside conda environment is still kind of undefined.
To ensure using the pip installed inside conda environment without having to type the lengthy
/home/username/anaconda/envs/env_name/bin/pip
, I wrote a shell function:Hope this is helpful to you.
I was facing a problem in installing a non conda package on anaconda, I followed the most liked answer here and it didn't go well (maybe because my anaconda is in F directory and env created was in C and bin folder was not created, I have no idea but it didn't work).
According to anaconda pip is already installed ( which is found using the command "
conda list
" on anaconda prompt), but pip packages were not getting installed so here is what I did, I installed pip again and then pip installed the package.see
is a non-conda package.For others who run into this situation, I found this to be the most straightforward solution:
Run
conda create -n venv_name
andsource activate venv_name
, wherevenv_name
is the name of your virtual environment.Run
conda install pip
. This will install pip to your venv directory.Find your anaconda directory, and find the actual venv folder. It should be somewhere like
/anaconda/envs/venv_name/
.Install new packages by doing
/anaconda/envs/venv_name/bin/pip install package_name
.This should now successfully install packages using that virtual environment's pip!
All above answers are mainly based on use of virtualenv. I just have fresh installation of anaconda3 and don't have any virtualenv installed in it. So, I have found a better alternative to it without wondering about creating virtualenv.
If you have many pip and python version installed in linux, then first run below command to list all installed pip paths.
You will get something like this as output.
Copy the path of pip which you want to use to install your package and paste it after sudo replacing
/home/prabhakar/anaconda3/bin/pip
in below command.This worked pretty well for me. If you have any problem installing, please comment.
For those wishing to install a small number of packages in conda with pip then using,
worked for me.
Explainaton
It seems, for me anyway, that
which pip
is very reliable for finding the conda env pip path to where you are. However, when usingsudo
, this seems to redirect paths or otherwise break this.Using the
$(which pip)
executes this independently of thesudo
or any of the commands and is akin to running/home/<username>/(mini)conda(3)/envs/<env_name>/pip
in Linux. This is because$()
is run separately and the text output added to the outer command.If you ONLY want to have a conda installation. Just remove all of the other python paths from your PATH variable.
Leaving only:
This allows you to just use
pip install *
and it will install straight into your conda installation.