MS Visual Code 中的项目结构为 Pycharm

Project Structure in MS Visual Code as Pycharm

我试图在 Visual Code 中打开一个 python 项目,但我在导入文件 "file not found" 时遇到错误。在 Pycharm 中,可以编辑项目结构并添加文件 "sources"。 Vscode怎么可能?

我尝试在“文件”>“将文件夹添加到工作区”中将文件夹添加到工作区。

我没有执行此操作的任何代码。该项目在 Pycharm 中运行良好,但在 vscode.

中运行良好

我决定写下我的解决方案,这就是我所做的。

  1. 打开您的文件所在的文件夹
  2. 保存工作区
  3. 打开 Launch.json 并进行如下编辑:

    { // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "cwd": "${workspaceFolder}",
            "env": {
                "PYTHONPATH": "${workspaceFolder}\folder1; 
                               ${workspaceFolder}\folder2\dada;
                               ${workspaceFolder}\folder3\dadadsada "
            }
        }
    ]}
    

现在我只需要转到 Debug > 运行 没有 Debugging 就可以了。