首页 > 解决方案 > 无法使用与“base”相同的 python 版本创建新的 conda 环境

问题描述

我希望为新项目创建新环境,以便可以在其中安装各种包。这些软件包不会影响我的基础环境。我的基础是 3.6.6 我希望我的新环境也应该是相同的 python 版本。但做不到。

这是我所做的:

conda create -n mynewenv # you must specify python version... why?
conda create -n mynewenv python=3.6.6 # so as to make it exact of 'base'. No, you can not specify 3.6.6 but only upto 3.6
conda create -n mynewenv python=3.6 # in the list to install it showed 3.6.8...why? I want only 3.6.6
conda create -n mynewenv python # somewhere I read that just by giving 'python' picks up the 'base' version. But no...it picked 3.7...why?

请提出正确的方法

标签: pythoncondavirtual-environment

解决方案


一种方法是仅将 Python 构建信息从base转储到需求文件中,然后将其用于新的 env 创建。这将确保 Python 与base中的 Python 完全相同。

conda list -n base --export | grep "^python=" > base-py.txt
conda create -n mynewenv --file base-py.txt

或者,如果您想要一个避免临时文件的单行:

conda create -n mynewenv --file <(conda list -n base --export | grep "^python=")

推荐阅读