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.)
@dannystaple
This is a very old gist though.
For now, selecting the python tab of the status bar at bottom left of vscode, and choosing the specific python env version provided anaconda3 always works for me.