虚拟环境具有错误的Python版本

huangapple go评论59阅读模式
英文:

Virtual Environment Has Wrong Python Version

问题

我必须使用一些依赖于Python 2.7的旧代码,但我使用Python 3。为了更改Python版本,我创建了一个虚拟环境(指定Python版本为2),但我的Python版本似乎没有更改。

这是我尝试的内容:

conda create -n python_two_env python=2.7

这创建了环境,然后我激活了它:

conda activate python_two_env

并使用以下命令检查了Python版本:

python --version

我得到了:

Python 3.10.10

为什么虚拟环境的Python版本不是2.7?

英文:

I have to use some old code that depends on Python 2.7 but I use Python 3. To change Python versions, I created a virtual environment (specifying Python to be version 2) but my python version didn't seem to change.

Here's what I tried:

conda create -n python_two_env python=2.7

This created the environment, then I activated it using:

conda activate python_two_env

and checked the python version using:

python --version

I got:

Python 3.10.10

Why is the virtual environment's python version not 2.7?

答案1

得分: 0

经过一些故障排除,我发现问题出在我的.bashrc文件中。具体来说,我定义了别名python=python3,这个别名优先于虚拟环境的Python版本。在注释掉该别名后,在虚拟环境中运行python --version返回Python 2.7.18 :: Anaconda, Inc.

英文:

After some troubleshooting, I found that the issue was in my .bashrc file. Specifically, I had defined the alias python=python3 which was being prioritized over the virtual environment's python version. After commenting out that alias, python --version in the virtual environment returns Python 2.7.18 :: Anaconda, Inc.

huangapple
  • 本文由 发表于 2023年6月26日 22:43:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76557750.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定