如何创建 Visual Studio Code Python 工作区? [英] How can I create a Visual Studio Code Python workspace?
问题描述
我正在尝试在 macOS 上的 Visual Studio Code 上设置 Python.我的计算机上安装了 Python 2.7 和 3.5 解释器.当我尝试创建我的第一个 Python 文件时,没有找到 import
模块.
I'm trying to set up Python on Visual Studio Code on macOS. I have Python 2.7 and 3.5 interpreters installed on my computer. When I attempted to create my first Python file, the import
modules were not found.
根据我看到的各种设置说明,我应该能够在工作区设置"中为我的解释器进行配置.但我不确定我是否有工作区、在哪里可以找到它或它是如何创建的.
According to the various setup instructions I've seen, I'm supposed to be able to configure for my interpreter in "workspace settings." But I'm not sure I have a workspace, where to find it or how it is created.
当我进入命令面板并尝试运行Python: Select Workplace Interpreter时,我收到一条错误消息:
When I go to the Command Palette and try to run Python: Select Workplace Interpreter I get an error that says:
请打开工作区以选择 Python 解释器
Please open a workspace to select the Python Interpreter
当我进入菜单文件 →偏好 →设置,工作场所设置标签呈灰色且处于非活动状态.
When I go to menu File → Preference → Settings, the Workplace Settings tab is greyed out and inactive.
在此页面上,在用户和工作区设置 它说,工作区设置文件位于项目中的 .vscode 文件夹下."
如果工作区与项目相关,那么如何创建项目?据我所知,Visual Studio Code 只有菜单 File 的菜单选项 →新建文件,而不是新建项目.
If a workspace is related to a project then how is a project created? After far as I can see, Visual Studio Code only has the menu option for menu File → New File, not New Project.
.vscode
文件夹在哪里?它是如何创建的?
Where is the .vscode
folder? How is it created?
推荐答案
Visual Studio Code 工作区是 Visual Studio Code 打开的目录.
A Visual Studio Code workspace is the directory which was opened by Visual Studio Code.
您应该在用户设置(文件 settings.json
)中创建一个虚拟环境并使用此虚拟环境制作 Visual Studio Code.
You should create a virtual environment and make Visual Studio Code using this virtual environment in user settings (file settings.json
).
示例:在 settings.json
中使用 venv
"python.pythonPath": "${workspaceRoot}/venv/bin/python"> 是当前工作空间中的虚拟环境目录.重新打开 Visual Studio Code.
Example: Set "python.pythonPath": "${workspaceRoot}/venv/bin/python"
in settings.json
with venv
is the virtual environment directory in the current workspace. Reopen Visual Studio Code.
这篇关于如何创建 Visual Studio Code Python 工作区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!