简体   繁体   English

使用本地pip安装导出conda环境

[英]Exporting a conda environment with local pip installs

I have exported my currently active environment with 我已导出当前活动的环境

conda env export > environment.yml

This is very convenient since it keeps track of both conda and pip installed packages. 这非常方便,因为它跟踪conda和pip安装的包。 However, I have a few packages (shapely and basemap for example) installed locally by pip from a .whl file from Christoph Gohlke's compiled packages for Windows. 但是,我有一些软件包(例如,整体和底图)由来自Christoph Gohlke的Windows编译软件包的.whl文件中的pip本地安装。 When I try to recreate my environment by 当我尝试通过重建我的环境时

conda env create -f environment.yml

pip returns with an error since it cannot find these packages in its index (obviously). pip返回错误,因为它无法在索引中找到这些包(显然)。 Is there a way to tell pip in the conda export step where to look for these local packages? 有没有办法在conda导出步骤中告诉pip在哪里查找这些本地包? The .whl files can be assumed to be in the same directory as the environment.yml file. 可以假定.whl文件与environment.yml文件位于同一目录中。

There's no way to actually get it to create entries for the .whl file automatically from what I'm aware of. 实际上没有办法让它根据我的意识自动创建.whl文件的条目。

The simplest way to get this to work is by manually altering the environment.yml file and adding the .whl file in the list under - pip: . .whl工作的最简单方法是手动更改environment.yml文件并在.whl - pip:下的列表中添加.whl文件。 I tried this by downloading the .whl package for nose and placing it in the same directory as my env.yml file, the structure looked like this: 我通过下载.whl包为nose并将它放在与我的env.yml文件相同的目录中来尝试这个,结构如下所示:

name: python3_test
dependencies:
- openssl=1.0.2h=1
- pip=8.1.2=py35_0
- python=3.5.1=5
- readline=6.2=2
- setuptools=23.0.0=py35_0
- sqlite=3.13.0=0
- tk=8.5.18=0
- wheel=0.29.0=py35_0
- xz=5.2.2=0
- zlib=1.2.8=3
- pip:
   - nose-1.3.7-py3-none-any.whl

If it is located in a different directory, just supply the directory. 如果它位于不同的目录中,则只提供该目录。 The path, of course, should be valid when issuing conda create env . 当然,在发布conda create env时,该路径应该是有效的。

The pip command issued when running conda env create -n <name> -f <file.yml> is a pretty straightforward install so the semantics of installing with pip from the command line should be similar. 运行conda env create -n <name> -f <file.yml>时发出的pip命令是一个非常简单的安装,因此从命令行使用pip 安装的语义应该类似。 Heck, you could even add the url for the .whl file in the requirements.yml and the installation would still go down smoothly. 哎呀,你甚至可以添加url.whl在文件requirements.yml和安装仍会往下走顺手。 Again, keeping the rest the same and using the url for downloading nose : 再次,保持其余部分相同并使用url下载nose

- pip:
   - https://pypi.python.org/packages/15/d8/dd071918c040f50fa1cf80da16423af51ff8ce4a0f2399b7bf8de45ac3d9/nose-1.3.7-py3-none-any.whl#md5=3135984cc9cfcbe5d9c46e166d6743b0

Using any url shouldn't cause any issue. 使用任何网址不应该导致任何问题。

Here is a specific example of an environment.yml that uses a URL to link to wheel files from Christoph Gohlke's compiled packages for Windows: 下面是environment.yml的一个具体示例,它使用URL链接到Christoph Gohlke为Windows编译的包中的wheel文件:

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

Reference: https://stackoverflow.com/a/35245610/1493069 参考: https//stackoverflow.com/a/35245610/1493069

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM