2018-07-17

python在virtual environment (venv) 環境時,vscode pylint會報import ... not found

在python的virtual environment工作時,vscode的pylint會說找不到套件,
因此我們要vscode的「Folder Settings」去指定 venv 下的pylint路徑,而不是global的pylint,
順便把python路徑也一起修改:

(Windows)
"python.pythonPath": "${workspaceFolder}/Scripts/python.exe"
"python.linting.pylintPath": "${workspaceFolder}/Scripts/pylint.exe"

(Linux)
"python.pythonPath": "${workspaceFolder}/bin/python"
"python.linting.pylintPath": "${workspaceFolder}/bin/pylint"


因外由於 pylint 對 python 3.7的支援性不太好(沒事就在噴runtime error錯誤),
我們可以安裝 preview version的pylint來解決:

pip install pylint astroid --pre -U

或改用flake8也行:
pip install flake8

用flake8記得修改vscode設定:
"python.linting.flake8Enabled": true
"python.linting.pylintEnabled": false
"files.trimTrailingWhitespace": true

沒有留言:

張貼留言