Conda version pip install -r requirements.txt --target ./lib

252,974

Solution 1

You can run conda install --file requirements.txt instead of the loop, but there is no target directory in conda install. conda install installs a list of packages into a specified conda environment.

Solution 2

To create an environment named py37 with python 3.7, using the channel conda-forge and a list of packages:

conda create -y --name py37 python=3.7
conda install --force-reinstall -y -q --name py37 -c conda-forge --file requirements.txt
conda activate py37
...
conda deactivate

Flags explained:

  • -y: Yes, do not ask for confirmation.
  • --force-reinstall: Install the package even if it already exists.
  • -q: Quiet, do not display progress bar.
  • -c: Channels, additional channels to search for packages. These are URLs searched in the order

Alternatively you can create an environment.yml file instead of requirements.txt:

name: py37
channels:
  - conda-forge
dependencies:
  - python=3.7
  - numpy=1.9.*
  - pandas

Use these commands to create and activate the conda environment based on the specifications in the Yaml file:

conda env create --file environment.yml
conda activate py37

Use this command to list the environments you have:

conda info --envs

Use this command to remove the environment:

conda env remove --name py37

New! The ansible-role dockpack.base_conda can manage conda environments on Linux, Mac and Windows, and can be used to create a docker image with custom conda environments.

Solution 3

You can always try this:

/home/user/anaconda3/bin/pip install -r requirements.txt

This simply uses the pip installed in the conda environment. If pip is not preinstalled in your environment you can always run the following command

conda install pip

Solution 4

A quick search on the conda official docs will help you to find what each flag does.

So far:

  • -y: Do not ask for confirmation.
  • -f: I think it should be --file, so it read package versions from the given file.
  • -q: Do not display progress bar.
  • -c: Additional channel to search for packages. These are URLs searched in the order

Solution 5

would this work?

cat requirements.txt | while read x; do conda install "$x" -p ./lib ;done

or

conda install --file requirements.txt -p ./lib
Share:
252,974

Related videos on Youtube

vineeth kanaparthi
Author by

vineeth kanaparthi

Updated on November 01, 2021

Comments

  • vineeth kanaparthi
    vineeth kanaparthi 11 months

    What is the conda version of this?

    pip install -r requirements.txt --target ./lib
    

    I've found these commands:

    while read requirement; do conda install --yes $requirement; done < requirements.txt
    

    But it doesn't tell how to specify --target ./lib

    • Charlie Parker
      Charlie Parker over 1 year
      did you try conda install --file requirements.txt?
  • Ataxias
    Ataxias about 3 years
    explaining the flags would be useful
  • ionox0
    ionox0 over 2 years
    Is there any reason why after the 2nd command above python3 is removed from the environment and python2 is the only one remaining?
  • bbaassssiiee
    bbaassssiiee over 2 years
    conda manages python environments, conda deactivate resets your shell, conda activate py37 sets your PATH.
  • Dr_Zaszuś
    Dr_Zaszuś over 2 years
    When I do this on my requirements.txt specifying versions of packages, I get InvalidVersionSpec: Invalid version '3.0.': empty version component
  • Remi Cuingnet
    Remi Cuingnet over 2 years
    There us no target directory for in conda install. However specifying a location for a virtual environment is possible with the --prefix optional argument (doc) and target environment specifications can be given with the --name or --prefix optional arguments (doc).
  • Hrvoje
    Hrvoje almost 2 years
    It could be usefull if you add where to put yaml file and how to install environment from it. I guess environment doesn't simply come to existence if you have yaml file.
  • Tms91
    Tms91 almost 2 years
    Just pip install -r requirements.txt works great for me.
  • EfratBlaier
    EfratBlaier over 1 year
    best solution for me: cat requirements.txt | while read x; do conda install -y "$x" ;done
  • Nikolay Fominyh
    Nikolay Fominyh over 1 year
    python -m pip install -r requirements.txt with activated conda env
  • Charlie Parker
    Charlie Parker over 1 year
    what do you mean by conda install installs a list of packages into a specified conda environment.? For me it usually installs it for whatever conda env is active at the moment.
  • phd
    phd over 1 year
    @CharlieParker The OP wanted to install to a different directory; pip can do this but conda probably cannot.
  • William Torkington
    William Torkington over 1 year
    @Ataxias was very right, the flag explanations are very helpful. +1!
  • john.da.costa
    john.da.costa about 1 year
    i like that one, it could possibly run slower, but more reliable.
  • arranjdavis
    arranjdavis 11 months
    Same as above, once I activated the conda environment, I just did pip3 install -r requirements.txt.