ModuleNotFoundError: No module named 'tensorflow'? - python

I got this error in Jupyter Notebook.
this may duplicate post but no any proper answer found
Neither below links helped me to solve this.
No module named tensorflow in jupyter
No module named tensor flow -- iPython notebook
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-b88de1945047> in <module>()
1 get_ipython().magic('matplotlib inline')
2 import numpy as np
----> 3 import tensorflow as tf
4 from tensorflow.contrib import rnn
5 import data_loader
ModuleNotFoundError: No module named 'tensorflow'
B:S -

enter image description here
I faced the same problem at first. I realized that in the conda-->envs -->
tensorflow-->Scripts-->idle.exe, is the python 3.5.5 shell. Where you can import tensorflow without any problems. So, I chaged the directory as C:\Users\Temp\Anconda3..... and then activated and deactived the tensorflow once. In the next step I entered the python mode and import tensorflow as tf worked right.

I had the same problem and I think I've found the solution!
See, I had installed both CPU and GPU versions of Tensorflow at the same time which apparently is wrong. Then, I uninstalled the GPU version, it didn't work this time either. So I uninstalled both of them and reinstalled the CPU version. It's working now.
BTW I'm on Win10(1803) and python 3.6.5 (not using anaconda.)

You can execute the following instructions and command to solve the issue: (do not include inverted commas)
Open Anaconda Prompt
type: "create --name py3-TF2.0 python = 3"
press "y" to continue
After successful completion:
type "conda activate py3-TF2.0"
type "pip install matplotlib"
type "pip install tensorflow==2.1.0"
type "conda deactivate"
type "pip install ipykernel"
type "conda install nb_conda_kernels"
Now exit the Anaconda prompt and open the Anaconda Navigator application. Switch to "py3-TF2.0" from the base environment using the Environment tab. Install Jupyter in the specified environment.
After successful installation, open Jupyter notebook and switch to "py3-TF2.0" kernel using Kernel Tab.
You're good to go for using TensorFlow 2.
Make Sure you use Anaconda 2020.02 or lower version.
As new version does not support TensorFlow 2.

Related

Tensorflow error " ImportError: DLL loaad failed with error code-1073741795"

Issue in importing TENSORFLOW(error code-1073741795 in jupyter notebook, Pycharm, Anaconda command line and in spyder. Howevery I am able to install successfully. But when I'm trying import then I am getting this error
"ImportError: DLL load failed with error code-1073741795".
I have install all the versions of VS redistributable.
I am using win 7 with 64 bit os. I tried to install on tensorflow on all the versions of python 3.6, 3.7
& 3.8. with different versions of tensorflow. Did anyone encountered with error code-1073741795???
ImportError: DLL load failed with error code-1073741795
Failed to load the native tensorflow runtime.
See https://www.tensorflow.org/install/errors
what does error code-1073741795 means?
How do we fix it.
I got an error like this when installing tensorflow. It was because tensorflow was not installed properly.
First, delete your current installed tensorflow completely.
Install Anaconda.
Make a new conda environment (this will help).
After creating a conda environment, activate it.
After activating, write: 'conda install tensorflow==1.15.0'
I am suggesting tensorflow 1.15.0 because I have found it more stable and better than any other version.
To test it is working properly, write:
python
This will activate python, then write:
import tensorflow as tf
print(tf.__version__)
You may get some warnings when importing tensorflow, but ignore the warnings, you will not get any errors. (if you get any error, comment)

ModuleNotFoundError: No module named 'tensorflow' Vs code

I am running on windows 10. I am having problems with importing TensorFlow. I am in Vs code. I installed tensorflow using pip3. And here is the error:
Traceback (most recent call last):
File "c:/Users/USER/PycharmProjects/tt/main.py", line 1, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
I created my project in pycharm.
I am using python 3.7.5 and TensorFlow 2.0.0. This is how I installed TF:
pip3 install tensorflow==2.0.0
please help I was having this problem for a week.
Thanks , In Advance
For your work/project, please try to create a new virtual environment and then install all your required packages.
Like this:
$ python3 -m venv env
Activate it:
$ source env/bin/activate
and then install the tensorflow package inside your virtual environment:
pip3 install tensorflow
I think you need to create environment separate
and then install tensorflow..
for more information regarding envirnoment Link
Do you have several different python environments on your pc? Which python interpreter are you using when you install tensorflow?
The Status Bar will show you the current interpreter in the lower left corner. Check whether it is the same with the one you use when you install tensorflow.
enter image description here
I was getting your exact error, but this worked for me:
File->settings
Workspace tab
Search for "interpreter"
Put the complete path to the python.exe you want to execute under "default interpreter path"
It seems VSCode either found (or included) an older version of python that couldn't find the things I installed with pip.
I am a bit of a python newb and I'm guessing the venv approach is superior, but I couldn't get that cooperating with VSCode on windows.

cannot import tensorflow - "Import Error: cannot import name 'self_check' "

I'm trying to use tensorflow-gpu. Using Anaconda, I installed the libraries and active both (tensorflow and tensorflow-gpu) I have also installed Keras in this anaconda environment as well
Next I launch Spider IDE within my Anaconda environment and run my py script, that is when I get the following error:
cannot import tensorflow - Import Error: cannot import name 'self_check'
I'm totally lost. Any recommendations?
Using Python 3.5
Thanks
pip install --upgrade tensorflow
or
you can uninstall the tensorflow and re-install it.

How do I install Theano and Lasagne in Anaconda (Jupyter)?

I have been trying to install Lasagne and Theano in Anaconda (Jupyter) on MacOS Sierra (10.12.3) to use this neural network: neural-storyteller
However when I try to import them in Jupyter:
import lasagne
import theano
I get this error:
ImportError Traceback (most recent call last)
<ipython-input-2-7d877a974cd7> in <module>()
----> 1 import lasagne
2 import theano
//anaconda/lib/python2.7/site-packages/lasagne/__init__.py in <module>()
11 section 'Install from PyPI' in the installation docs for more details:
12 http://lasagne.readthedocs.org/en/latest/user/installation.html#install-from-pypi
---> 13 """)
14 else:
15 del theano
ImportError: Could not import Theano.
Please make sure you install a recent enough version of Theano. See
section 'Install from PyPI' in the installation docs for more details:
http://lasagne.readthedocs.org/en/latest/user/installation.html#install-from-pypi
My guess is that I installed Theano on a different version of python because when I make a normal python file (.py) and import lasagne and theano they work. Also, when I look in the anaconda folder in the User directory there is no theano folder but there is one in the miniconda2 folder (/Users/Pit/miniconda2/pkgs/theano-0.9.0-py27_0).
I could just use a .py file, but I also need the caffe library which I could only get to work with Anaconda python.
Does anybody know how to install the right version of theano that works in Anaconda (Jupyter)?
Any help would be much appreciated
I had faced the same issue. I think it's because Theano installation was not proper. So here is what I did and it started working after that :
In Anaconda Prompt
conda install theano
Follow through the installation. It would probably ask for some confirmations.
Then,
pip install -r https://raw.githubusercontent.com/Lasagne/Lasagne/master/requirements.txt
After that,
pip install https://github.com/Lasagne/Lasagne/archive/master.zip
I think that should do the trick. It started working after that in my case. Restart the kernel once.
For more context : https://pypi.org/project/Lasagne/
You should check which jupyter and which python is being called by using the command:
which python
If you do:
which jupyter
they should be in the same directory. For example:
$:/home/spark : which jupyter
~/anaconda2/bin/jupyter
$:/home/spark : which python
~/anaconda2/bin/python
If they're not the same, then that could explain why you cannot import some libraries (because they're installed under a different python instance).
Unless you need both, I would remove either anaconda or miniconda to make things simpler and less confusing.
Theano works fine with Anaconda and in Jupyter in my experience.

importerror no module named tensorflow windows

import tensorflow as tf Traceback (most recent call last):
File "<ipython-input-5-41389fad42b5>", line 1, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
I am getting the following error after installation of tensorflow in anaconda using windows. I have followed the tensorflow installation steps
At first it was running properly but when i tried to uninstall and reinstall tensorflow, this error pops up. I tried uninstalling Anaconda itself and reinstalling but was of no help. Tensorflow is getting installed but when i try the import step it shows the above error.
Solved: Python 3.6 is incompatible with tensorflow and had to create tensorflow environment for python 3.5.
conda create -n tensorflow python=3.5 anaconda
Activated it in command prompt and launched spyder from it which changed my python version to 3.5. Now was able to import tensorflow properly.
If you installed tensorflow using Anaconda inside an Anaconda environment, you will need to activate this environment. Only then can you import tensorflow.

Categories