简体   繁体   中英

ModuleNotFoundError: No module named 'tensorflow'?

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 - python和anaconda版本截图

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)

  1. Open Anaconda Prompt
  2. type: "create --name py3-TF2.0 python = 3"
  3. press "y" to continue

After successful completion:

  1. type "conda activate py3-TF2.0"
  2. type "pip install matplotlib"
  3. type "pip install tensorflow==2.1.0"
  4. type "conda deactivate"
  5. type "pip install ipykernel"
  6. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM