Proper relative imports: “Unable to import module”

前端 未结 4 1729
南方客
南方客 2021-02-12 11:34

I have a project structured like this:

.
└── myapp
    ├── app.py
    ├── models
    │   ├── hello.py
    │   └── world.py
    └── requirements.txt
4条回答
  •  梦谈多话
    2021-02-12 11:54

    In your your .vscode/settings.json (in the root directory of your workspace) you need these two lines:

    one to use the pylint in your virtual environment (if you have one) so that pylint is aware of it. You'll want to adjust the below if your pylint or virtual environment is located in a different place.

      "python.linting.pylintPath": "${workspaceFolder}/api/venv/bin/pylint"
    

    and one, as Shtefan mentions above, to let pylint know where the python part of your project is:

      "python.linting.pylintArgs": [
        "--init-hook",
        "import sys; sys.path.append('${workspaceFolder}/api')"
      ]
    

    This additional line may be helpful if you don't already have vscode setup with your virtual environment, once again you may have to modify if your virtual environment path does not match the below.

      "python.pythonPath": "${workspaceFolder}/api/venv/bin/python",
    

提交回复
热议问题