Pylint “unresolved import” error in visual studio code

自闭症网瘾萝莉.ら 提交于 2019-11-27 21:09:13

In your workspace settings, you can set your python path like this:

{
    "python.pythonPath": "/path/to/your/venv/bin/python",
}

This issue has already been opened on GitHub: https://github.com/Microsoft/vscode-python/issues/3840 There are 2 very useful answers, by MagnuesBrzenk and SpenHouet.

The best solution for now is to create a .env file in your project root folder. Then add a PYTHONPATH to it like this:

PYTHONPATH=YOUR/MODULES/PATH

and in your settings.json add

"python.envFile": ".env"  
sps

If you have this code in your settings.json file, delete it

{    
    "python.jediEnabled": false
}

Alternative way: use the command interface!

cmd/ctrl + shift + p > Python: Select Interpreter > choose the one with the packages you look for

I was able to resolved this by enabling jedi in .vscode\settings.json

"python.jediEnabled": true

Reference from https://github.com/Microsoft/vscode-python/issues/3840#issuecomment-456017675

I have a different solution: my VSCode instance had picked up the virtualenv stored in .venv, but was using the wrong Python binary. It was using .venv/bin/python3.7; using the switcher in the blue status bar, I changed it to use .venv/bin/python and all of my imports were resolved correctly. I don't know what VSCode is doing behind the scenes when I do this, nor do I understand why this was causing my problem, but for me this was a slightly simpler solution than editing my workspace settings. I hope it helps someone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!