using pip as a low priority 'channel' in conda environment - python

Is there a way to use pip as a 'fallback' option for some packages in a conda environment, like you can have multiple prioritized conda channels?
For normal conda channels, my environment.yml would be as follows:
name: my_env
channels:
- defaults
- conda-forge
dependencies:
- some-package>=1.2.3
Where some-package would be installed from default channels if possible, or conda-forge otherwise. It would fail if neither channel has the appropriate package version.
The environment.yml with pip:
name: my_env
channels:
- defaults
- conda-forge
dependencies:
- pip
- pip:
- some-package>=1.2.3
Where some-package would always come from pip.
But what I want is something like this:
name: my_env
channels:
- defaults
- conda-forge
dependencies:
- some-package>=1.2.3
- pip
- pip:
- some-package>=1.2.3
Where the package would come from defaults first, else conda-forge, or else from pip.
However, this gives a ResolvePackageNotFound error before trying pip. Is there any way to achieve this?

I've read somewhere that conda shall be extended to allow satisfying dependencies with pip-installed packages. But I cannot find the reference with a quick search, and I don't think it's a production-ready feature anyway. And what I remember was not conda installing pip packages, but conda accepting already present packages that have been installed by pip.
Anaconda packages define their dependencies in terms of other Anaconda packages. Therefore, conda resolves dependencies of Anaconda packages within its own world of packages and metadata. Some packages don't even have the same name in Anaconda channels and on PyPI.
In other words: No, I don't think that what you want is possible. You'll have to call pip when you want something installed by pip.

Related

Automating install of a mix of conda-forge and pip python libraries

I have a python package for which I need some other python libraries that are installed via conda-forge. However, it also needs a small number of libraries that are installed via pip. What is the best way to automate the installation of this mix of conda-forge and pip libraries when someone installs my package?
Conda's environment.yml file can take both conda dependencies and pip dependencies. I'll paste in from the docs:
name: stats2
channels:
- javascript
dependencies:
- python=3.9
- bokeh=2.4.2
- numpy=1.21.*
- nodejs=16.13.*
- flask
- pip
- pip:
- Flask-Testing
The pip array at the end lists stuff you'd like to pull from PyPI rather than from conda repositories.

Cannot find package for Python 3.7.8

I am completly new to Conda and I have been struggling for a day without success.
I would like to use the pvtrace module. The documentation specifically says to run the following commands to install the package:
conda create --name pvtrace-env python=3.7.8
conda activate pvtrace-env
conda install Rtree
pip install pvtrace
I have the following error:
PackagesNotFoundError: The following packages are not available from current channels:
- python=3.7.8
I have Anaconda 3 which original Python version is 3.9. I installed the version 3.7, but it did not solve my problem.
Not sure why, but the defaults (main/anaconda) channels are missing specifically the Python 3.7.8 build. This is available through Conda Forge, so, instead try
## one should prefer to list all known package at creation
conda create -n pvtrace-env -c conda-forge python=3.7.8 pip rtree
conda activate pvtrace-env
pip install pvtrace
Alternatively, use a YAML file:
pvtrace-env.yaml
name: pvtrace-env
channels:
- conda-forge
dependencies:
- python=3.7.8
- rtree
- pip
- pip:
- pvtrace
which is used as:
conda env create -n pvtrace-env -f pvtrace-env.yaml

How to update a package in /opt/conda/anaconda/lib/python3.7/site-package

I am trying to update the h2o package. When I run conda list h2o, this package is shown as
Name Version Build Channel
h2o 3.34.0.3 pypi_0 pypi
When I run conda update h2o it tells me.
PackageNotInstalledError: Package is not installed in prefix.
prefix: /opt/conda/anaconda
package name: h2o
How do I update this package?
#cel has correctly answered in his comment, all the credit goes to her/him!
You can see the conda list output that the package channel is pypi, this means that the package has been installed using pip.
If you want to upgrade it in place. This seems to be the simplest solution however mixing conda and pip packages in a conda environment is not advised since it can lead to dependency issues.
pip install --upgrade h2o
# check your installation
pip check
# No broken requirements found.
If you wan to uninstall it and replace it by a conda package.
# uninstall it
pip uninstall h2o
# install it with conda
conda install -c conda-forge h2o
Note: I've used the conda-forge channel but you can choose to use the default channel.
Maybe a better / safer solution could be to create a new conda environment from scratch with a fresh version of the package.
# will create a new env called my-env and containing the latest
conda create -c conda-forge -n my-env h2o
You will need to add also the other packages you need.

Python package isnt upgraded despite running `conda install`

I have a conda enviroment called Vik. One of the packages installed is TBB (tbb=2018.0.5). I want to upgrade to version 2019.5 or later because my code returns this warning. NumbaWarning: The TBB threading layer requires TBB version 2019.5 or later
Thus, I went on and installed the latest TBB (at least this is what I believe). I havent kept the original message log but It looked normal to me. I am under the impression that the package was successfully installed. When I try to install it again this is what I get
(base) C:\Windows\system32>conda activate Vik
(Vik) C:\Windows\system32>conda install -c conda-forge tbb
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
but it appears that i am still calling the old version 2018.0.5. The numba warning that I need to upgrade tbb is still there when I run my application and conda env export -n Vik > environment.yml generates the following list. At the bottom of the list below you can clearly see that the package hasnt been updated. Note that the package doesnt appear under the pip section of the environment.yml shown below, hence it should be a conda package.
What am I doing wrong?
name: Vik
channels:
- anaconda
- conda-forge
- defaults
dependencies:
- anyio=3.2.0=py37h03978a9_0
- argon2-cffi=20.1.0=py37he774522_1
- async_generator=1.10=py37h28b3542_0
- attrs=21.2.0=pyhd3eb1b0_0
- babel=2.9.1=pyh44b312d_0
- backcall=0.2.0=py_0
.....
.....
.....
- sqlite=3.35.3=h2bbff1b_0
- tbb=2018.0.5=he980bc4_0
- terminado=0.9.1=py37_0
The conda install -c conda-forge tbb directive translates to the imperative
With the channel conda-forge prioritized, ensure that the currently activated environment has some version of tbb installed.
Since tbb is already installed, that directive is already satisfied.
If you want a newer version, either use conda update -c conda-forge tbb or specify a version, e.g., conda install -c conda-forge tbb=2021.

Warning after I run the command "conda env create -f environment.yml"

After I run the conda env create -f environment.yml in Conda, I receive the following warning:
Warning : you have pip-installed dependencies in your environment file, but you do not list pip itself as one of your conda dependencies...
What does this mean and what should I be doing instead?
When creating an environment the warning disappeared by including - pip explicitly in the yaml file. Yes, it is a bit awkward because if your environment has pip packages you already have declared that you used pip packages with - pip:
The yaml file would look like:
# Packages omitted for simplicity
name: myenv
channels:
- anaconda
- conda-forge
- defaults
dependencies:
- python
- scipy
- pip
- pip:
- datetime
At the time of creating a new environment from scratch this warming can be avoided by explicitly installing pip, for instance with: conda create -n env_with_pip python=3.7 numpy pip
In your environment yml file under list of the packages you install through conda you must also add pip as a package to be installed. This installs the pip, and so your pip packages can be installed using this pip.
Previously pip was shipped with conda but now we have to explicitly install pip when using conda

Categories