【发布时间】:2021-10-17 17:33:41
【问题描述】:
我使用 pyenv 在我的 mac (Big Sur os) 上安装 Python 3.8.11 和 3.9.6,并将 3.8.11 设置为我想要用于创建虚拟环境的 Python 版本(遵循指令here)。但是,即使我已经将系统设置为使用 3.8.11,产生的虚拟环境似乎使用的是 Python 3.8.2。
这就是我所做的:
-
通过 Homebrew 安装 pyenv
-
通过
pyenv install 3.X.X安装 Python 3.8.11 和 3.9.6 -
将
eval "$(pyenv init -)"添加到~/.bash_profile这是一个空文件 -
在终端中输入
pyenv local 3.8.11,然后在终端中输入pyenv versions以确认正在使用 3.8.11:$ pyenv versions system * 3.8.11 (set by /Users/me/projects/sample/.python-version) 3.9.6
但是,当我在终端输入python3 -V 时,我的系统显示正在使用 Python 3.8.2:
$ python3 -V
Python 3.8.2
当我输入which python3时,系统显示python3的路径(大概是3.8.2)为/usr/bin/python3:
$ which python3
/usr/bin/python3
我不记得 Python 3.8.2 何时/如何安装在我的机器上。我确实尝试使用brew uninstall python@3.8 卸载但系统返回:
$ brew uninstall python@3.8
Error: No available formula or cask with the name "python@3.8". Did you mean python@3.8, python@3.9, python@3.7 or python-yq?
因为我被卡住了,还是赌了一把,我输入了python3 -m venv virtual_env来创建我的虚拟环境,希望新环境是我想要的python版本,但是在使用source virtual_env/bin/activate激活我的虚拟环境后,我进入了python -V 并确认生成的环境使用的是 Python 3.8.2 而不是 3.8.11:
(virtual_env) me$ python -V
Python 3.8.2
谁能告诉我我错过了什么/做错了什么?解决这个问题的最佳方法是什么?
【问题讨论】:
-
不知道是不是变化很大,但你试过
brew uninstall python@3.8.2吗? -
brew uninstall python@3.8.2导致Error: No available formula or cask with the name "python@3.8.2". Did you mean python@3.8, python@3.9 or python@3.7?
标签: python python-3.x python-venv pyenv