简体   繁体   English

Conda (Python) 虚拟环境不能从 Windows 移植到 Linux

[英]Conda (Python) Virtual Environment is not Portable from Windows to Linux

On my Windows 10 machine, I created a virtual environment using the following command:在我的 Windows 10 机器上,我使用以下命令创建了一个虚拟环境:

>conda env export > environment.yml 

I tried re-creating the virtual environment using the yml file on the Windows system and it worked fine.我尝试在 Windows 系统上使用 yml 文件重新创建虚拟环境,效果很好。 Then I transferred environment.yml to my Linux machine (Ubuntu 16.04.1) with the same version of conda and python and ran the following in the terminal:然后我使用相同版本的 conda 和 python 将 environment.yml 传输到我的 Linux 机器(Ubuntu 16.04.1)并在终端中运行以下命令:

$ conda env create -f environment.yml

I get the following error:我收到以下错误:

Using Anaconda Cloud api site https://api.anaconda.org使用 Anaconda Cloud api 站点https://api.anaconda.org
Fetching package metadata .......获取包元数据.......
Solving package specifications: .解决封装规格:.
Error: Packages missing in current linux-64 channels:错误:当前 linux-64 频道中缺少软件包:
- jpeg 8d vc14_0 - jpeg 8d vc14_0
- libpng 1.6.22 vc14_0 - libpng 1.6.22 vc14_0
- libtiff 4.0.6 vc14_2 - libtiff 4.0.6 vc14_2
- mkl 11.3.3 1 - mkl 11.3.3 1
- numpy 1.11.1 py35_1 - numpy 1.11.1 py35_1
- openssl 1.0.2h vc14_0 - openssl 1.0.2h vc14_0
- pyqt 4.11.4 py35_7 - pyqt 4.11.4 py35_7
- qt 4.8.7 vc14_9 - qt 4.8.7 vc14_9
- tk 8.5.18 vc14_0 - 传统知识 8.5.18 vc14_0
- vs2015_runtime 14.0.25123 0 - vs2015_runtime 14.0.25123 0
- zlib 1.2.8 vc14_3 - zlib 1.2.8 vc14_3

Most of these packages are available in the linux repo of conda, but with a different flavor.大多数这些软件包都可以在 conda 的 linux 存储库中找到,但具有不同的风格。 For instance, if I remove vc14_0 from the line that contains the jpeg package in the yml file, that would work just fine.例如,如果我从 yml 文件中包含 jpeg 包的行中删除 vc14_0,那将工作得很好。 The package vs2015_runtime is not available in linux at all.软件包 vs2015_runtime 在 linux 中根本不可用。 Nothing gets returned when you run:运行时不会返回任何内容:

conda search vs2015_runtime". 

How can I export my virtual environment in a portable way when working cross-platform, so that all the packages can be installed in Linux as well?如何在跨平台工作时以可移植的方式导出我的虚拟环境,以便所有软件包也可以安装在 Linux 中?

Here is the content of my environment.yml .这是我的environment.yml的内容。

It looks like you are fetching packages compiled with Microsoft Visual C/C++ Compiler (the vc part of the name).看起来您正在获取使用 Microsoft Visual C/C++ 编译器(名称的vc部分)编译的包。 Those packages won't be ABI compatible from Linux as you are trying to do.这些软件包与您尝试做的 Linux 的 ABI 不兼容。 Simply target the packages that are not Windows-specific.只需针对非 Windows 特定的软件包即可。

When exporting your environment, use the option --from-history.导出环境时,请使用 --from-history 选项。

conda env export --from-history > environment.yml

It will export just the libs you explicitly installed, and not the dependencies:它只会导出您明确安装的库,而不是依赖项:

Usually some dependencies are platform specific, like your visual studio dependency above.通常,某些依赖项是特定于平台的,例如上面的 Visual Studio 依赖项。 Also the default conda env export put platform specific info in the libs.此外,默认的 conda env 导出将特定于平台的信息放入库中。

It will prevent a lot of troubles and make your export file multi-platform.它将避免很多麻烦并使您的导出文件多平台。

Extra tip: always install a lib referencing its version number (eg: conda install pandas=1.2.1).额外提示:始终安装引用其版本号的库(例如:conda install pandas=1.2.1)。 Without the version, the command above will export the dependencies without a version, ruining your environment.如果没有版本,上面的命令将导出没有版本的依赖项,破坏您的环境。

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

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