MacOS python 命令未从 VS Code 终端找到活动的 Conda 环境
我最近买了一台新的 M1 MacBook - 第一次使用 Mac - 并立即下载了 Miniconda 以进行一些 Python 工作的设置。
我创建了一些虚拟环境(例如 conda create -n myenv python=3.8
),但在活动时,python
命令默认为 Mac 的 Python 2.7,从而阻止我从VS Code 中的命令行。例如:
conda activate myenv
(myenv)% which python
/usr/bin/python
where
显示了默认的 2.7 安装和正确的虚拟环境版本,但我无法访问它。
(myenv)% where python
/usr/bin/python
/Users/user/miniconda3/envs/myenv/bin/python
知道如何让 VS Code 找到合适的 Python 版本吗?它似乎可以从内置终端运行,但不能从 VS Code 运行。
操作系统:Monterey 12.2.1
VS 代码:1.65.0
Miniconda:4.10.1
I recently got a new M1 MacBook - first time ever using a Mac - and immediately downloaded Miniconda to get it set up for some Python work.
I created some virtual environments (e.g. conda create -n myenv python=3.8
) but when active, the python
command defaults to Mac's Python 2.7, preventing me from running scripts from the command line in VS Code. For example:
conda activate myenv
(myenv)% which python
/usr/bin/python
where
shows me the default 2.7 installation and the correct virtual environment version, but I can't access it.
(myenv)% where python
/usr/bin/python
/Users/user/miniconda3/envs/myenv/bin/python
Any idea how to get VS Code to find the proper Python version? It seems to work from the built in terminal, just not VS Code.
OS: Monterey 12.2.1
VS Code: 1.65.0
Miniconda: 4.10.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试在 MacOS 中利用
python3
而不是python
吗?或者您可以尝试将
python.exe
重命名为其他名称,例如/usr/bin/python
下的python2.7
?Could you try to take advantage of
python3
instead ofpython
in the MacOS?Or you can try to rename the
python.exe
to something others, such aspython2.7
under the/usr/bin/python
?所以问题是,在windows中,你可以改变路径,但在mac中,如果你不选择版本,就会出现这样的情况,例如:
它将运行Python 2.7,因为它已安装,并且运行最低的安装版本。因此尝试使用
或在终端中指定版本
So the problem is, that in windows, you can change the path, but in mac there is this thing, that if you don't select the version, for example:
It will run Python 2.7, because it is installed, and it runs the lowest installed version. So try using
or specify the version in the terminal