简体   繁体   中英

Conda unable to create different Python version environment

I am trying to create a new conda Python 2.7 environment. 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

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.

Any idea what is wrong and how to solve this?

(I am working on 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.)

Here are some additional info.

  1. When env is activated commands:
  • which python gives- /opt/local/bin/python
  • type python gives- python is /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
  1. When env is not activated commands:
  • which python gives- /opt/local/bin/python
  • type python gives- python is /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

After running conda list output is this: 在此处输入图像描述

TL;DR With conda3, specify the Python 2.7 version fully, eg, 2.7.18.

When I tried to reproduce your command in my own conda3 environment, I got this error:

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:

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.

Alternative: use 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. On your old machine, you might have had conda2 installed, which would explain why it worked.

Thanks to @FlyingTeller for pointing out conda2 is not necessary, though.

I had the same problem with my 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. They go into the details on how to fix this.

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

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,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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