Combining conda environment.yml with pip requirements.txt

前端 未结 3 1643
傲寒
傲寒 2020-12-02 07:58

I work with conda environments and need some pip packages as well, e.g. pre-compiled wheels from ~gohlke.

At the moment I have two files: environment.yml

相关标签:
3条回答
  • 2020-12-02 08:41

    One can also use the requirements.txt directly in the YAML. For example,

    name: test-env
    dependencies:
      - python>=3.5
      - anaconda
      - pip
      - pip:
        - -r file:requirements.txt
    

    Basically, any option you can run with pip install you can run in a YAML. See the Advanced Pip Example for a showcase of other capabilities.

    0 讨论(0)
  • 2020-12-02 08:55

    Pip dependencies can be included in the environment.yml file like this (docs):

    # run: conda env create --file environment.yml
    name: test-env
    dependencies:
    - python>=3.5
    - anaconda
    - pip
    - pip:
      # works for regular pip packages
      - docx
      - gooey
      # and for wheels
      - http://www.lfd.uci.edu/~gohlke/pythonlibs/bofhrmxk/opencv_python-3.1.0-cp35-none-win_amd64.whl
    

    It also works for .whl files in the same directory (see Dengar's answer) as well as with common pip packages.

    0 讨论(0)
  • 2020-12-02 08:58

    Just want to add that adding a wheel in the directory also works. I was getting this error when using the entire URL:

    HTTP error 404 while getting http://www.lfd.uci.edu/~gohlke/pythonlibs/f9r7rmd8/opencv_python-3.1.0-cp35-none-win_amd64.whl
    

    Ended up downloading the wheel and saving it into the same directory as the yml file.

    name: test-env
    dependencies:
    - python>=3.5
    - anaconda
    - pip
    - pip:
      - opencv_python-3.1.0-cp35-none-win_amd64.whl
    
    0 讨论(0)
提交回复
热议问题