When using the Anacoda Python distribution, what is the best way to install a PyPi package that isn't available directly through Anaconda? For now I'm using:
conda pipbuild [pypi_name]
conda install --use-local [package_spec]
But I'm unclear if this is the best way and if conda update --all will update these packages when updates are made available. I'm also unclear what the point of binstar is when PyPi already exists.
I will disagree with the accepted response and note that pip install [some-pypi-package] is often the best way to install PyPi packages in Conda environments.
While the packages won't be managed by the Conda package manager, they will still be managed by the Anaconda environment. It will download the correct version of the package for the active Python install and update it correctly using the pip package manager.
When using Anaconda, you should turn to conda before pip when you can, but you don't lose any of the replicability benefits of using Anaconda when you use pip.
Anaconda recently published a doc that supports this: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment
If you want to build conda packages for PyPI packages, the recommended way is to use conda skeleton pypi package and use conda build package on the recipe that it creates. To install the package, use conda install --use-local package (here and elsewhere, package is the name of the PyPI package you wish to install).
You will need to update the recipe each time the package is updated.
You can also use pip to install these packages. There are two disadvantages: firstly, these packages won't be managed by conda at all. Secondly, these packages will not work if your default python version is different from the python version you are using in conda.
Since version 4.6.0, Conda has improved its interoperability with pip:
Conda and pip have historically had difficulties getting along. Pip
hasn’t respected Conda’s environment constraints, while Conda has been
all too happy to clobber pip-installed software. It’s a mess. Conda
4.6.0 adds preview support for better interoperability. With this interoperability, Conda can use pip-installed packages to satisfy
dependencies, and can even remove pip-installed software cleanly and
replace them with Conda packages when appropriate. There’s still room
for improvement before pip and Conda are hunky-dory BFFs, but we hope
this is a good start. This feature is disabled by default right now
because it can significantly impact Conda’s performance. If you’d like
to try it, you can set this condarc setting:
conda config --set pip_interop_enabled True
So, the way to get PyPI packages into conda (at the time of writing this) seems to be:
pip install <package>
If you want conda to replace the PyPI packages with its own (where possible), just run:
conda update --all
Given that the above setting is made. Conda marks its own channels as higher priority than pip, thus packages will be replaced.
There is a caveat (thanks #alfalfasprout): Since conda did not install the pypi packages they are not included in conda export --from-history. You'd have to get the list (from conda or pip) and install these packages separately via pip, like you did originally. Thus, for people using the conda history functionality, there is at least a second step needed.
Related
In a python project, I'm using conda and poetry together. conda is used to create the environment and to install poetry and python. The project dependencies are mainly managed using poetry.
However, there are some packages which I would like to install using conda as it is more convenient. Such examples include spyder, ipykernel and packages using CUDA.
The problem is that these packages installed by conda of course install dependencies themselves. If I install some other packages using poetry afterwards, these dependencies might get replaced by other versions which are again incompatible with the packages installed by conda.
Is there any way to have common dependencies which are used by both conda and poetry?
Listing all dependencies of all children recursively is not an option!
I stumbled on this post:
Install of R in miniconda
https://community.rstudio.com/t/install-of-r-in-miniconda/19755
Is it possible to install R in miniconda?
As I understand it miniconda is a package manager for Python only according to this definition:
Miniconda
Miniconda is a free minimal installer for conda. It is a small, bootstrap version of Anaconda that includes only conda, Python, the packages they depend on, and a small number of other useful packages, including pip, zlib and a few others. Use the conda install command to install 720+ additional conda packages from the Anaconda repository.
https://docs.conda.io/en/latest/miniconda.html
Or is it possible to use it with R?
I know Anaconda 3 offers R support.
Thanks.
Miniconda (the light, non-GUI version of Anaconda) gives you access to conda on the command line, and with that you can install R, along with some common packages, as follows:
conda install r r-essentials --channel conda-forge
And any further R packages you need:
conda install r-<package-name> --channel conda-forge
The "Conda" ecosystem is language-agnostic, it delivers whatever you ask for (if it exists in the repository) and installs the necessary platform binaries, but I would suggest creating a virtual environment specific to each "language platform", to ensure isolation.
Example:
conda create -n r_env r-essentials r-base
conda activate r_env
conda list
And work within this environment to run R and install new packages.
To leave the virtual environment:
conda deactivate
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.
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.