我正在尝试运行下面的代码来从YAML文件创建虚拟Python环境。我在Ubuntu服务器上的命令行中运行代码。虚拟环境名为py36。当我运行下面的代码时,我收到以下消息。环境也不会被创建。这个问题是否因为我有几个包而不是使用pip而不是Anaconda来安装?有谁知道如何解决这个问题?
我按照以下示例创建了YAML文件:
https://datascience.stackexchange.com/questions/24093/how-to-clone-python-working-environment-on-another-machine
conda env create -f py36.yml
name: py36
channels:
- anaconda
- cvxgrp
- conda-forge
- defaults
dependencies:
- beautifulsoup4=4.6.3=py36_0
- patsy=0.5.1=py36_0
- sqlite=3.25.3=ha441bb4_0
- tk=8.6.8=ha441bb4_0
- asn1crypto=0.24.0=py36_1003
- ca-certificates=2018.11.29=ha4d7672_0
- certifi=2018.11.29=py36_1000
- cffi=1.11.5=py36h5e8e0c9_1
- clangdev=4.0.0=default_0
- cryptography=2.3.1=py36hdbc3d79_1000
- cryptography-vectors=2.3.1=py36_1000
- cycler=0.10.0=py_1
- fftw=3.3.8=h470a237_0
- freetype=2.9.1=h6debe1e_4
- glpk=4.65=h16a7912_1
- gmp=6.1.2=hfc679d8_0
- icu=58.2=h0a44026_1000
- idna=2.8=py36_1000
- kiwisolver=1.0.1=py36h2d50403_2
- lapack=3.6.1=1
- libiconv=1.15=h1de35cc_1004
- libpng=1.6.35=ha92aebf_2
- libxml2=2.9.8=hf14e9c8_1005
- lightgbm=2.2.1=py36hfc679d8_0
- llvmdev=4.0.0=default_0
- matplotlib=2.2.3=py36h0e0179f_0
- metis=5.1.0=3
- mkl_fft=1.0.6=py36_0
- mkl_random=1.0.1=py36_0
- mlxtend=0.13.0=py_1
- openblas=0.2.20=8
- openmp=4.0.0=1
- openssl=1.0.2p=h1de35cc_1002
- pandas=0.23.4=py36hf8a1672_0
- pycparser=2.19=py_0
- pyopenssl=18.0.0=py36_1000
- pyparsing=2.2.0=py_1
- pysocks=1.6.8=py36_1002
- python=3.6.6=h4a56312_1003
- pytz=2018.5=py_0
- selenium=3.141.0=py36h470a237_0
- tbb=2018_20171205=0
- urllib3=1.24.1=py36_1000
- cvxcanon=0.1.1=py36_0
- cvxpy=1.0.6=py36_0
- ecos=2.0.5=py36hf9b3073_0
- multiprocess=0.70.4=py36_0
- scs=1.2.6=py36_0
- appnope=0.1.0=py36hf537a9a_0
- backcall=0.1.0=py36_0
- blas=1.0=mkl
- cvxopt=1.2.0=py36hb579ef3_0
- decorator=4.3.0=py36_0
- dill=0.2.8.2=py36_0
- dsdp=5.8=hb579ef3_0
- fastcache=1.0.2=py36h1de35cc_2
- gsl=2.4=h1de35cc_4
- intel-openmp=2019.0=117
- ipykernel=4.8.2=py36_0
- ipython=6.4.0=py36_0
- ipython_genutils=0.2.0=py36h241746c_0
- jedi=0.12.0=py36_1
- jupyter_client=5.2.3=py36_0
- jupyter_core=4.4.0=py36h79cf704_0
- libcxx=4.0.1=h579ed51_0
- libcxxabi=4.0.1=hebd6815_0
- libedit=3.1.20170329=hb402a30_2
- libffi=3.2.1=h475c297_4
- libgcc=4.8.5=hdbeacc1_10
- libgfortran=3.0.1=h93005f0_2
- libopenblas=0.3.3=hdc02c5d_2
- libsodium=1.0.16=h3efe00b_0
- mkl=2018.0.3=1
- ncurses=6.1=h0a44026_0
- numpy=1.15.4=py36h6a91979_0
- numpy-base=1.15.4=py36h8a80b8c_0
- parso=0.2.1=py36_0
- pexpect=4.6.0=py36_0
- pickleshare=0.7.4=py36hf512f8e_0
- pip=10.0.1=py36_0
- prompt_toolkit=1.0.15=py36haeda067_0
- ptyprocess=0.5.2=py36he6521c3_0
- pygments=2.2.0=py36h240cd3f_0
- python-dateutil=2.7.3=py36_0
- pyzmq=17.0.0=py36h1de35cc_1
- readline=7.0=hc1231fa_4
- scikit-learn=0.20.1=py36h4f467ca_0
- scipy=1.1.0=py36h28f7352_1
- setuptools=39.2.0=py36_0
- simplegeneric=0.8.1=py36_2
- six=1.11.0=py36h0e22d5e_1
- suitesparse=5.2.0=he235d88_0
- toolz=0.9.0=py36_0
- tornado=5.0.2=py36_0
- traitlets=4.3.2=py36h65bd3ce_0
- wcwidth=0.1.7=py36h8c6ec74_0
- wheel=0.31.1=py36_0
- xz=5.2.4=h1de35cc_4
- zeromq=4.2.5=h378b8a2_0
- zlib=1.2.11=hf3cbc9b_2
- pip:
- absl-py==0.2.2
- astor==0.6.2
- bleach==1.5.0
- cython==0.28.3
- gast==0.2.0
- grpcio==1.12.1
- h5py==2.8.0
- html5lib==0.9999999
- keras==2.2.0
- keras-applications==1.0.2
- keras-preprocessing==1.0.1
- markdown==2.6.11
- pillow==5.1.0
- protobuf==3.5.2.post1
- pyramid-arima==0.6.5
- pyyaml==3.12
- sklearn==0.0
- statsmodels==0.9.0
- tensorboard==1.8.0
- tensorflow==1.8.0
- termcolor==1.1.0
- tqdm==4.23.4
- werkzeug==0.14.1
- xlrd==1.1.0
prefix: /Users/username/anaconda2/envs/py36
conda env create -f py36.yml
Collecting package metadata: done
Solving environment: failed
ResolvePackageNotFound:
- libgfortran==3.0.1=h93005f0_2
- pyzmq==17.0.0=py36h1de35cc_1
- python==3.6.6=h4a56312_1003
- prompt_toolkit==1.0.15=py36haeda067_0
- libiconv==1.15=h1de35cc_1004
- sqlite==3.25.3=ha441bb4_0
- six==1.11.0=py36h0e22d5e_1
- cryptography==2.3.1=py36hdbc3d79_1000
- openssl==1.0.2p=h1de35cc_1002
- libxml2==2.9.8=hf14e9c8_1005
- libcxxabi==4.0.1=hebd6815_0
- matplotlib==2.2.3=py36h0e0179f_0
- ptyprocess==0.5.2=py36he6521c3_0
- readline==7.0=hc1231fa_4
- libedit==3.1.20170329=hb402a30_2
- libgcc==4.8.5=hdbeacc1_10
- xz==5.2.4=h1de35cc_4
- pickleshare==0.7.4=py36hf512f8e_0
- appnope==0.1.0=py36hf537a9a_0
- scipy==1.1.0=py36h28f7352_1
- cvxopt==1.2.0=py36hb579ef3_0
- jupyter_core==4.4.0=py36h79cf704_0
- dsdp==5.8=hb579ef3_0
- ncurses==6.1=h0a44026_0
- tk==8.6.8=ha441bb4_0
- ecos==2.0.5=py36hf9b3073_0
- wcwidth==0.1.7=py36h8c6ec74_0
- scikit-learn==0.20.1=py36h4f467ca_0
- libopenblas==0.3.3=hdc02c5d_2
- traitlets==4.3.2=py36h65bd3ce_0
- libsodium==1.0.16=h3efe00b_0
- ipython_genutils==0.2.0=py36h241746c_0
- fastcache==1.0.2=py36h1de35cc_2
- numpy==1.15.4=py36h6a91979_0
- numpy-base==1.15.4=py36h8a80b8c_0
- zlib==1.2.11=hf3cbc9b_2
- libffi==3.2.1=h475c297_4
- pygments==2.2.0=py36h240cd3f_0
- icu==58.2=h0a44026_1000
- gsl==2.4=h1de35cc_4
- libcxx==4.0.1=h579ed51_0
- suitesparse==5.2.0=he235d88_0
- zeromq==4.2.5=h378b8a2_0
不,PyPI不是问题。相反,它失败了,因为YAML包含特定于平台的构建约束,但您正在跨平台进行传输。具体来说,检查失败的软件包(例如,six=py36h0e22d5e_1
)上的构建号,我可以看到它们对应于osx-64
平台上的软件包,但是您正在尝试在linux-64
平台上安装,因此构建约束是无法解决的。
最简单的解决方案是从环境定义导出中排除构建信息。
conda env export -n py36 -f py36.yml --no-builds
如果通过Conda在linux-64
上找不到某些软件包,仍然会有问题。如果是这种情况,您可能需要找到其他通道(或检查PyPI),切换版本或完全删除依赖项。大多数包看起来都很标准。
不是那么重要,但你可以安全地从你的频道中删除cvxgrp
。该频道只服务于过时版本的cvxopt
,仅适用于osx-64
。
实际上,环境在conda安装(即dependencies
)部分下保持平台构建细节。来自OP的样本:
- zlib=1.2.11=hf3cbc9b_2
,hf3cbc9b_2
是一个特定于平台的版本标签。你必须删除它。
如果你经常在平台之间切换(例如OSX < - > Linux),请阅读@merv的答案,这是你未来env export
做的正确的事情。
目前,像我一样,只想修复它,你可以手动完成或运行sed
:
sed 's/\(.*[[:alnum:]]\)=[[:alnum:]][[:alnum:].-_]*/\1/' environment.yml > env.yml
。这将处理特定于平台的标记,而不触及文件的pip
部分。
然后你可以用env.yml
再试一次:
conda env create -f env.yml
请注意,可能会出现特定于平台的软件包如果在删除版本标签后,Conda仍然抱怨,您将不得不相应地手动清理软件包。例如,我带来了一个从Linux到Mac的
environment.yml
,其中没有定义包libgcc-ng=9.1.0
,libstdcxx-ng=9.1.0
,libgfortran-ng=7.3.0
;我用手取下它们。
一旦这样的清洁完成,我的conda env create -f env.yml
就像一个魅力。