【发布时间】:2017-12-18 22:02:16
【问题描述】:
我正在尝试让 PyLint 自动在 vscode 中使用正确的 conda 环境,但仍然出现导入错误:[pylint] E0401:Unable to import 'django',尽管:
【问题讨论】:
标签: python visual-studio-code anaconda conda pylint
我正在尝试让 PyLint 自动在 vscode 中使用正确的 conda 环境,但仍然出现导入错误:[pylint] E0401:Unable to import 'django',尽管:
【问题讨论】:
标签: python visual-studio-code anaconda conda pylint
你必须在这个 conda 环境中安装pylint。
使用activate env_name (Windows) 或source activate env_name 激活给定环境。
在这个环境中安装pylint:
conda install pylint # or 'pip install pylint'
最后,重启 vscode。
来源:https://github.com/DonJayamanne/pythonVSCode/wiki/Troubleshooting-Linting
【讨论】:
即使在正确安装 python 和 pylint 之后,由于 Visual Studio 代码中 pylintArgs 的错误配置,也会遇到问题。
使用以下用户设置解决了问题
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_django"
]
【讨论】:
您只需要确保您在使用 conda 本身创建的同一虚拟环境中工作。基本上你需要启用“Python:启用 Linting 命令”。通常在左下角,VS Code 会告诉你正在工作的环境。如果您通过 anaconda-navigator GUI 打开 VS Code(即使您使用正确的相应环境打开它)。 VS Code,默认情况下使用(基本)conda 环境打开编辑器。这可能是混乱。具有讽刺意味的是,Linting 正在做它打算做的事情。通过左下角的提示,只需将环境更改为您为项目定制的环境。关闭编辑器,并完全关闭 anaconda-navigator GUI。只需使用终端更新和升级您的系统(如果您使用的是基于 Linux 的操作系统)。快速更新 conda,以确保不会出错。重启 anaconda-navigator,然后打开 VS Code。如果你运行编辑器的内部终端,你会看到它通过 (base) 环境打开,它会自动切换到正确的对应 conda 环境,它自己会这样做;
source /home/user/anaconda3/bin/activate
(base) user@machine:~$ source /home/user/anaconda3/bin/activate
(base) user@machine:~$ conda activate your_env
(your_env) user@machine:~$
PS - 我个人发现使用 Anaconda Navigator 让我的生活更轻松。
也许可以通过 VS 代码文档https://code.visualstudio.com/docs/python/linting 来进一步阅读。黑客攻击快乐!
【讨论】: