There is a common problem we often encounter when using vscode.
[pylint] E0401:Unable to import 'tensorflow'
- First make sure that both the
python.pythonPath
andpython.linting.pylintPath
are configured correctly in the WORKSPACE SETTINGS, especilly for the cases when you use anaconda or virtualenv
{
// We can run `type python` to get the python path after activating the virtual env
// Notice that we should set the pythonPath to the bin location of python, but NOT the path of site-packages.
"python.pythonPath": "/Users/kael/anaconda2/envs/tensor/bin/python",
"python.linting.pylintPath": "/Users/kael/anaconda2/bin/pylint"
}
- Then, for most situtations, you need to restart the project by opening the
.code-workspace
file. - Choose the python environment for vscode. Check this article first: https://code.visualstudio.com/docs/python/environments#_choosing-an-environment. Or you can select the python tab of the status bar at the bottom of vscode, and select
"/Users/kael/anaconda2/envs/tensor/bin/python"
(according to the example above, you might have to choose your own env.)
In my case - although I'd set up a venv, with the installed packages, and chose that venv in vscode, it wasn't using the venv pylint to run my code. I suspect I need to uninstall the base python pylint so it doesn't get to choose that.