多python环境下,如何调整vscode的默认python编译器?
发布于 作者:苏南大叔 来源:程序如此灵动~
偶然发现:苏南大叔的苹果电脑里面,有多个python
环境,相互之间产生了比较混乱的情况。目前在使用vscode
调试python
过程中,出现了比较奇特的现象:在vscode
自带的terminal
面板中,python
和pip
命令出现了不一致的情况。就是:pip
安装的包,在vscode
默认的python
之中并不能被识别出来。
大家好,这里是苏南大叔的程序如此灵动博客,这里记录苏南大叔和计算机代码的故事。本文描述,如何调整vscode
的python
插件中的默认解释器。可以解决在vscode
的默认terminal
中,python
不能识别pip
安装的包的问题。本文测试环境:mac
,vscode@1.68.0
,python@3.8.5
。
问题截图
在python
文件上,右键run python file in terminal
。这个功能来自于vscode
的python
插件。
如截图所示,虽然pip
安装了itchat
包,但是默认的python
解释器却依然不能识别到itchat
。而另外一个python
解释器,却是能够识别到这个itchat
的。
调整解释器
这里依然调出vscode
的命令面板,输入:
Python:Select Interpreter
就可以选择一个默认的python
解释器了。由于pip
安装的包能够被anaconda3
的base
环境下的python
所识别。这里就设置默认的python
解释器为anaconda3
的base
环境下的python
了。
当然,在这里选择一个合适的路径就行,并不是推荐使用上述截图中的路径。因为这个问题的答案是因人而异的。
相关链接
- https://newsn.net/say/mac-python-reinstall.html
- https://newsn.net/say/pip-mirror.html
- https://newsn.net/say/vscode-execute-python.html
- https://newsn.net/say/vscode-coderunner.html
综述
多python
环境简直就是噩梦,但是由于各个版本的python
总是有各种各样的理由,相互不兼容。所以,谨慎处理python
的各个版本,是个永恒的话题。


