

用 Visual Studio Code 的时候如何设置 Virtualenv
source link: https://sexywp.com/howto-set-virtualenv-in-vscode-macos.htm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

这两天,写了个小小的 Python 代码,基本功能实现了,需要完善一下的时候,突然想起来,VS Code 那么好用,应该也支持 Python 吧,我就不用在命令行用 vim 写那么辛苦了,主要是对中文字符的渲染不好看。
没想到,相当尴尬了,用 VS Code 打开以后,无法识别我在项目文件夹设置的 virtualenv 环境。而 Python 扩展的官方帮助赫然写着是支持的。介绍的设置方法什么的,完全都是扯淡,毫无帮助,还说会什么自动识别之类的,都是不起作用的。想起来了著名的直升机飞行员笑话。
最后,救世主还是 SO(StackOverflow),只有一个 老哥提到了一句 ,在用 VS Code 打开一个文件夹的时候,就创建了一个 Workspace ,然后,你的目录下多了一个隐藏目录 .vscode ,这个目录里有一个 settings.json 文件,这个文件里,设定了一个 Workspace 级别的配置。
如果你使用 ⌘ + ⇧ + P 来设置 Python: Select Interpreter 的时候,是无论如何都没法发现你的项目目录下的 bin 目录的。这就很尴尬了。所以,方法是直接在 Workspace 的 settings.json 中,手动编辑加入使用的解释器路径:
{ "python.linting.pylintEnabled": true, "python.linting.enabled": true, "python.pythonPath": "./bin/python3.7" }
然后,重启 VS Code,就可以发现完全兼容了现在这个项目目录下的 virtualenv 环境了。又可以愉快的 Python 了。
我解释一下,我一般是进入一个项目目录,然后执行 virtualenv . ,这个项目目录会变成一个 virtualenv 环境,只会影响这一个项目,不会影响别的项目,这样我可以在每个不同的项目里,使用不同的 Python 环境。这会在项目根目录下多出来一些目录,bin,include,lib 等,加入到 .gitignore 文件就好了。
Recommend
-
150
October 2017 (version 1.18) Update 1.18.1: The update addresses these issues. Downloads:
-
189
Out of the blue, Microsoft jumps into the editor wars with an incredible offering that gives Sublime Text an overwhelming run for its money. In fact, it just might surpass it! So come along, as I demonstrate the ins, the outs, the tips, the tech...
-
210
Page not found – theinfogrid.com
-
183
Visual Studio和VS Code中的Rust
-
106
See what is new in the Visual Studio Code April 2018 Release (1.23)
-
117
June 2018 (version 1.25) Downloads: Windows | Mac | Linu...
-
50
-
72
I recently wrote about My Top VSCode Tips and Tricks and among them was Debugging. In this article, I'll cover how to debug...
-
3
吕毅 发表于 28 分钟前 同样的程序,在使用 Visual Studio 调试的时候和直接运行的时候相比,总会有一些细微之处是不同的。大多数时候这些不同可以忽略,但是一旦这些不同是我们产品需求的一部分的时候,你可能就会发现调...
-
2
Visual Studio Code代理设置 VPS小白 >
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK