Fix No name “python” in module Solution for VisualStudioCode.

haomin
2 min readMay 20, 2018

I just started learning about TensorFlow, and the first time I installed it on my Mac there are some issues (For me, I am using the Visual Studio Code, and Anaconda):

I installed TF and tested in the prompt, everything works. However, after I open the VSC try to import a sub-module from TF, there is an error:

no name "python" in module ...

and it is caused by this line of code:

from TensorFlow.python.data import Dataset

However, this line works fine:

import tensorflow as tf

I tested in prompt multiple times, I just keep getting the error, after searching online, seems some people are getting the same error, and there seems to have no useful answer:

https://stackoverflow.com/questions/49601292/python-not-finding-tensorflow-module-under-anaconda

Here is the solution to this problem:

Basically, the problem is caused by pylint.

For VSC, the python extension, use pylint for intellisense of python. Pylint seems to have a bug with the sub-module. For me, the error only shows in VSC and not in prompt.

I solved this problem by doing the following steps:

Click “Code” -> Click “Preferences” -> Click “Settings”

Now in the settings, you have a search bar on top, search:

python.linting.pylintEnable and set it to false

Now there is alternative for linting, I am using the pep8 as a example here since it come with Anaconda, search this

python.linting.pep8Enabled and set it to true

Now pylint is not the default linter anymore, we are now using the pep8. Just to make sure, quit VSC and reopen it. there should not be any error anymore.

I am fairly sure this is a problem with pylint, instead of the TF you installed. By default, the Microsoft python extension in the VSC is using pylint as the linting tool. By changing it to pep8 or other we can avoid the error.

--

--