Reputation: 4558
I'm a newbie trying to execute the code in first_steps_with_tensor_flow.ipynb locally on Windows 10. I have installed Anaconda Navigator 1.8.2, created an environment where I've installed, among others, tensorflow
package. I then launch Visual Studio Code from Anaconda and run
import math
from IPython import display
from matplotlib import cm
from matplotlib import gridspec
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
from sklearn import metrics
import tensorflow as tf
from tensorflow.python.data import Dataset
The last line is marked with red in VS Code, saying E0401:Unable to import 'tensorflow.python.data'. Running, I get ModuleNotFoundError: No module named 'tensorflow'. However, if I change the last line to print (tf.__version__)
I do get 1.2.1
as output, so obviously Tensorflow is installed. Oddly VS Code complains E1101:Module 'tensorflow' has no __version__ member
, but that line works.
What am I doing wrong here?
Upvotes: 3
Views: 3797
Reputation: 49
Pylint was not installed for VS to work with. I found this by searching (in VS) for lint, inspired by Haomin above. A messagebox appeared and the first suggestion was to install pylint. "pip install pylint". I clicked this and it all worked! This has taken ages to find.
Upvotes: 1
Reputation: 1559
are you using Visual Studio Code (VSC) or just pylint in general? I found out the reason why this is happening.
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 tofalse
Now there is alternative for linting, I am using the pep8 as a example here since it come with the anaconda, search this
python.linting.pep8Enabled
and set it totrue
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.
Upvotes: 4
Reputation: 4868
Tensorflow is on version 1.7.0 currently and you have version 1.2.1 installed. Having reviewed the tensorflow repository, the tensorflow.python.data was first used in 1.4.0-rc0, before that it was in contrib.
I'd suggest to upgrade to the current version and retry. Alternatively look up the correct path in version 1.2.1.
Upvotes: 3
Reputation: 5043
Use tf
not tensorflow
.
You have imported tensorflow as tf
, not tensorflow
.
import math
from IPython import display
from matplotlib import cm
from matplotlib import gridspec
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
from sklearn import metrics
import tensorflow as tf
from tf.python.data import Dataset
Upvotes: -2