I am using a conda environment to install a package and this package have dependencies that's not available in conda, so I have to use pip to install some additional packages in the conda environment. After I did all these:
I tested both:
pip list
and
conda list
And found that some dependencies occur in pip list but not in conda list. Is this OK? Do the packages installed by pip in conda enviroment also effect in this envorment?
Yes, I use a combination of pip install and conda install when setting up the environment for a project I'm working on. It works fine.
However, it is documented here that this combination can lead to issues: https://www.anaconda.com/blog/using-pip-in-a-conda-environment
According to that doc, you ought to first use conda to install as many of your packages as possible, then use pip to install the rest afterwards.
Related
The pip was installed per each environment and which pip returns proper(and different) location for different conda environments.
I am not using any external scripts for the installation. It's vanilla pip install and also tried python -m pip install. Also tried to install with conda. In all of these cases, installing it for env1 will uninstall it from env2 and vice versa. No matter from which env I am installing, all envs will use the same version that was installed last.
Not sure if it's relevant, but I am using WSL2.
What could go wrong? What else should I check?
I still have no idea what is causing this behavior but at least found a workaround - using pip --ignore-installed option:
conda activate your_target_env
pip install --ignore-installed torch torchvision torchaudio
This will not uninstall other versions of pytorch installed inside other conda environments. And both environments will work with their versions of pytorch.
I was trying to install pycryptodome, python-jose-cryptodome using pip within anaocnda3 environment.
I got this error:
ERROR: Failed building wheel for pycryptodome
I have tried many versions many solutions(latest versions, specified version, with python 3.8 or 3.7, using requirements text without cache and even alone installation) but nothing worked for me :(. Any solution?
While using pip in an anaconda environment is allowed and fine, issues may arise when using pip and conda together, this was clearly mentioned in the conda docs.
One of the best practices when installing packages in an anaconda environment is to use conda for search and install before using pip.
So instead of directly using pip, try to :
Search for pycryptodome in anaconda packages repo
conda search pycryptodome
pycryptodome is available in anaconda repo .
The next step is to install pycryptodome :
conda install -c anaconda pycryptodome
or if you want to use conda-foge channel :
conda install -c conda-forge pycryptodome
this should get pycryptodome installed into your env
To use a requirements.txt file with conda :
conda install --yes --file requirements.txt
Summary : Best Practices Checklist When Using Pip in a Conda Environment
Use pip only after conda
install as many requirements as possible with conda, then use pip
pip should be run with –upgrade-strategy only-if-needed (the default)
Do not use pip with the –user argument, avoid all “users” installs
Use conda environments for isolation
create a conda environment to isolate any changes pip makes
environments take up little space thanks to hard links
care should be taken to avoid running pip in the “root” environment
Recreate the environment if changes are needed
once pip has been used conda will be unaware of the changes
to install additional conda packages it is best to recreate the
environment
Store conda and pip requirements in text files
package requirements can be passed to conda via the –file argument
pip accepts a list of Python packages with -r or –requirements
conda env will export or create environments based on a file with
conda and pip requirements .
you can read more about this topic here on anaconda website, and on conda docs
When I install a package through pip (since it was not available on Anaconda), it also pulls all dependencies. It seems it will use the pip versions of the dependencies, even if conda versions (same name) are available.
How can I easily install a pip package, but use conda for the dependencies where such a package exists?
There is no easy way, I suspect. Create a virtual environment, install all anticipated dependencies using conda and then install the main package using pip without -U/--upgrade. pip seeing dependencies installed will not install them again.
I have installed a fresh anaconda v4.4. I realized that python packages can be installed using both conda and pip. What is the effect of using pip to install python packages instead of conda when using anaconda? Will the pip-installed libraries cease to function? I am using python v3
EDIT: I don't think the question is a duplicate of What is the difference between pip and conda?
That question explains the difference between pip and conda but does not talk about the effect of using pip when conda can be used.
Everything might keep working if you use pip to install vs conda. However, Conda cannot manage dependencies that pip has installed - it cannot upgrade them, or remove them. More importantly, conda will install a package even if its already been installed with pip! Try this test:
conda create -n testenv python=3
conda activate testenv
pip install numpy
conda install scipy
You will see from the third command that conda will want to re-install NumPy, even though it has already been installed with pip. This can cause problems if there are C libraries whose linking is different, or something like that. In general, whenever possible, use conda to install packages into conda environments.
I have the anaconda distribution of python installed on my machine. Before installing anaconda, i had pip installed. Right now, my system uses the previous version of pip rather than the anaconda version. In particular
arjuns-mbp:~ Arjun$ which pip
/usr/local/bin/pip
arjuns-mbp:~ Arjun$ which easy_install
/Users/Arjun/anaconda/bin/easy_install
arjuns-mbp:~ Arjun$ which python
/Users/Arjun/anaconda/bin/python
The result is that if i call a pip install, it won't add it to my anaconda version of python. So far i haven't had an issue simply using easy_install to add packages to anaconda, but it would be nice to know what causes this discrepancy and how to fix it
EDIT
i tried using conda install pip, it doesn't work. When I do
conda list
pip showed up before and after a conda install
You probably need to conda install pip.
pip should already come with Anaconda automatically. How did you install Anaconda? No matter, though, you can just conda install pip to make sure you have a version of pip that is tied to the Anaconda distribution.
From there you can create environments as much as you like to install whatever new trial-run software tools using conda create -n env_name python pip