简体   繁体   English

conda无法创建不同的Python版本环境

[英]Conda unable to create different Python version environment

I am trying to create a new conda Python 2.7 environment.我正在尝试创建一个新的 conda Python 2.7 环境。 For this purpose I am typing this in terminal:为此,我在终端中输入:

conda create -n my_env_name python==2.7

After activating created environment ( conda activate my_env_name ) and checking Python version ( python --version ) I am getting Python 3.10.2激活创建的环境( conda activate my_env_name )并检查 Python 版本( python --version )后,我得到了Python 3.102。

No matter which Python version I am trying to use in the new environment I am always getting Python 3.10.2 answer when checking the Python version.无论我尝试在新环境中使用哪个 Python 版本,在检查 ZA7F5F35426B927411FC9231B5638217Z 版本时,我总是得到Python 3.10.2答案。

Any idea what is wrong and how to solve this?知道什么是错的以及如何解决这个问题吗?

(I am working on iMAC, Chip Apple M1, macOS Monterey 12.1) (我正在研究 iMAC、Chip Apple M1、macOS Monterey 12.1)

(After doing the same on my old machine everything works fine and after checking the Python version in a newly created environment I am getting Python 2.7.18.) (在我的旧机器上执行相同操作后,一切正常,在新创建的环境中检查 Python 版本后,我得到 Python 2.7.18。)

Here are some additional info.这里有一些额外的信息。

  1. When env is activated commands:当 env 被激活命令:
  • which python gives- /opt/local/bin/python which python给出 - /opt/local/bin/python
  • type python gives- python is /opt/local/bin/python type python给出 - python 是 /opt/local/bin/python
  • echo $PATH gives- /opt/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/uros/Desktop/iraf-main/unix/hlib/ecl.sh://Users/uros/.iraf/bin:/opt/anaconda3/envs/py27/bin:/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin echo $PATH给出 - /opt/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/uros/Desktop/iraf-main/unix/hlib/ecl.sh://Users/uros /.iraf/bin:/opt/anaconda3/envs/py27/bin:/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/ X11/bin:/库/Apple/usr/bin
  1. When env is not activated commands:当 env 未激活命令时:
  • which python gives- /opt/local/bin/python which python给出 - /opt/local/bin/python
  • type python gives- python is /opt/local/bin/python type python给出 - python 是 /opt/local/bin/python
  • echo $PATH gives- /opt/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/uros/Desktop/iraf-main/unix/hlib/ecl.sh://Users/uros/.iraf/bin:/opt/anaconda3/bin:/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin echo $PATH给出 - /opt/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/uros/Desktop/iraf-main/unix/hlib/ecl.sh://Users/uros /.iraf/bin:/opt/anaconda3/bin:/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin: /图书馆/苹果/usr/bin

After running conda list output is this:运行 conda conda list output 后是这样的: 在此处输入图像描述

TL;DR With conda3, specify the Python 2.7 version fully, eg, 2.7.18. TL;DR使用 conda3,完全指定 Python 2.7 版本,例如 2.7.18。

When I tried to reproduce your command in my own conda3 environment, I got this error:当我尝试在我自己的 conda3 环境中重现您的命令时,出现此错误:

PackagesNotFoundError: The following packages are not available from current channels:

  - python==2.7

However, when I specified the version of Python 2.7 fully, it worked for me:但是,当我完全指定 Python 2.7 的版本时,它对我有用:

conda create -n p27 python==2.7.18
conda activate p27
python --version

shows that Python 2.7.18 is the default Python in that environment.显示 Python 2.7.18 是该环境中的默认 Python。

Alternative: use conda2替代方案:使用 conda2

With Anaconda3/Miniconda3, the default Python will be Python 3.x, whereas with Aanconda2/Miniconda2, the default Python would be Python 2.7.x. With Anaconda3/Miniconda3, the default Python will be Python 3.x, whereas with Aanconda2/Miniconda2, the default Python would be Python 2.7.x. On your old machine, you might have had conda2 installed, which would explain why it worked.在你的旧机器上,你可能已经安装了 conda2,这可以解释它为什么工作。

Thanks to @FlyingTeller for pointing out conda2 is not necessary, though.不过,感谢@FlyingTeller 指出 conda2 不是必需的。

I had the same problem with my M1 Mac.我的 M1 Mac 也有同样的问题。

As it turns out when working with python versions below 3.8 according to this post here there is no support for running osx-arm64.事实证明,根据这篇文章,在使用低于 3.8 的 python 版本时,这里不支持运行 osx-arm64。 They go into the details on how to fix this.他们 go 详细介绍了如何解决此问题。

You can also follow this blog post from Danny Cunningham How to Manage Conda Environments on an Apple Silicon M1 Mac Manage both ARM64 and x86 Python environments using conda您还可以关注 Danny Cunningham 的这篇博文 How to Manage Conda Environments on an Apple Silicon M1 Mac Manage both ARM64 and x86 Python 环境使用 conda

in your case it should be something like:在你的情况下,它应该是这样的:

CONDA_SUBDIR=osx-64 conda create -n my_env_27_x86 python=2.7 

I hope this helps,我希望这有帮助,

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

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