I'm trying to set a conda environment using a requirements.txt
file that a coworker shared with me. My coworker uses Python in a Mac without Anaconda, and I'm using it in a Windows machine with Anaconda. The file requirements.txt
was generated with the command pip freeze
and looks like this:
absl-py==0.7.1
affine==2.3.0
agate==1.6.0
agate-dbf==0.2.0
agate-excel==0.2.1
agate-sql==0.5.2
...
After checking the answer of this question, I tried the following in the Anaconda terminal:
conda create --name my-env-name --file requirements.txt
Which fails with the following error message:
PackagesNotFoundError: The following packages are not available from current channels:
- appscript==1.0.1
- style==1.1.0
- senticnet==1.3
- scikits.optimization==0.3
...
My understanding is that this happens because those packages are not available in the Anaconda package installation channels, and that they should be installed instead via pip
with my conda environment activated, using pip install -r requirements.txt
The problem is that this list of packages is very long, and I would like to avoid having to manually check and separating which packages are included in Anaconda channels and which should be installed via pip
. Then, is there a way to tell Anaconda to create an environment by automatically recognizing the packages included in its channels, installing them, and then installing the rest using pip
?
requirements.txt
with condaThere's no problem at all using a requirements.txt
file when creating a conda environment.
In fact, you can also set additional channels at creation time:
conda create --name my-env-name --file requirements.txt --channel <NAME_OF_CHANNEL>
for example, in the case of the first package you mention, you can install it from anaconda
channel. So you could run:
conda create --name my-env-name --file requirements.txt --channel default --channel anaconda
Why using default
channel first? Well, just to give preference to the default one (the priority of channels is specified by the order they are listed: higher priority from left to right).
Well, when no conda channel can provide any of your required packages, there are several alternatives:
Install through conda those packages available in any of its channels.
Install through pip the rest.
Create a conda environment.yml
file:
conda env export > environment.yml
When you need to recreate this environment, then you can do:
conda env create --name my-env-name --file environment.yml
and it will install the packages using conda, will install pip, and then will install those packages only available with the latter one.
This approach has good and bad properties:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With