英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论