如何使用特定的 python 版本创建 conda 环境?

我已经安装了 miniconda3,因为我希望有一个 Python 版本3.3.0的环境,所以我通过

conda create -n "myenv" python=3.3.0

然而,当我激活环境通过

conda activate myenv

Python 有版本2.7.15和 path

/usr/bin/python

而且 ipython 有 python 3.6.8版本和 path

/home/myname/.local/bin/ipython

我可以访问正确的巨蟒与 python3

/home/myname/miniconda3/envs/myenv/bin/python3

但是,ipython3又是 Python 版本3.6.8。

conda install python=3.3.0

让情况保持不变。

一个解决方案是通过

python3 -m IPython

然而,虽然这对于 python工作良好,我在这里得到错误消息

/home/myname/miniconda3/envs/myenv/bin/python3: No module named IPython

在特定的环境中,是否可以使用命令 pythonipython访问 python 版本3.3.0,也就是说,不需要在 .bashrc中设置别名?

编辑:

结果表明,如果您选择 version 3.3而不是3.3.0并同时选择@ilmarinen 的答案,则不会出现这个问题

conda create -n "myenv" python=3.3 ipython

一切工作正常,python以及 ipython结果版本 python 3.3.5

131288 次浏览

You need to install ipython as well into your given environment

conda create -n "myenv" python=3.3.0 ipython

The conda environments are prepended to your PATH variable, so when you are trying to run the executable "ipython", Linux will not find "ipython" in your activated environment (since it doesn't exist there), but it will continue searching for it, and eventually find it wherever you have it installed.

To create an environment named py33 with python 3.3.0, using the channel conda-forge and a list of packages:

conda create -y --name py33 python==3.3.0
conda install -f -y -q --name py33 -c conda-forge --file requirements.txt
conda activate py33
...
conda deactivate

Alternatively you can use

conda env create -f environment.yml

to use an environment.yml file instead of requirements.txt:

name: py33
channels:
- conda-forge
dependencies:
- python=3.3.0
- ipython

Use this command to remove the environment:

conda env remove -n py33

I had similar issue. And I could't find many useful discussions.

The problem for me was I have alias pointing python to miniconda python hardcoded in my shell config file when I execute conda init zsh. Somehow the init process copies the alias and always reload that, thus overwrites the "correct" version.

After conda create -n py27 python=2.7 (my system default is 3.6), the version was correctly installed at miniconda3/envs/py27/bin/python. But the activated evironment python was not pointing to it, as indicated by which python,even if I deleted updated my shell config.

In the end it was solved by 'reverse' conda init (remove the generated conda function in .zshrc), remove alias, and re-init.

I guess other shell is using the same mechanism.