I have installed tensorflow with anaconda successfully. There is a virtual environment named tensorflow, and I activate it.
But in Jupyter Notebook, I tried to import tensorflow, only to get an error: No module named 'tensorflow'.
NOTE: should be activate tensorflow and NOT activate tensorfow
Related
I have created a tf2 tensorflow environment using Anaconda. I can import tensorflow no issue via the command prompt. When I activate this environment and launch Jupyter notebook, I get:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_20912/1332388178.py in <module>
1 # TensorFlow and tf.keras
----> 2 import tensorflow as tf
3
4 # Helper libraries
5 import numpy as np
ModuleNotFoundError: No module named 'tensorflow'
I have created run this to add the kernel to Jupyter (although I thought it just launched using the current active conda environment anyway).
python -m ipykernel install --user --name <Environment_Name>
But still no joy when explicitly using the tf2 kernel in Jupyter. Although jupyter seems to be starting off the active tf2 environment anyway.
[I 13:58:30.178 NotebookApp] Kernel shutdown: 603e39de-2b2e-4228-86ce-b135811ea301
[I 13:58:30.438 NotebookApp] Kernel started: 98f24818-ae84-4947-9c88-9b1814d9c768, name: tf2
[I 13:59:49.915 NotebookApp] Saving file at /tensorflow/Fashion MNIST.ipynb
Create a new environment for tensorflow using below code:
conda create -n tf tensorflow python=3.5
conda activate tf
As you have already created tf2 environment, activate the same environment in cmd prompt as below:
conda activate tf2
then insatll:
conda install pip
pip install tensorflow
Now, Select the "tf2"(you created) in anaconda environments and open the JUPYTER notebook in the same environment and type:
import tensorflow as tf
if there is no error - tensorflow successfully installed.
You can check the tensorflow version -
print(tf.__version__)
Further, you can install any package using !pip install package_name in Jupyter Notebook.
I am trying to build a ANN model using Tensorflow library on Spyder. Afte ı set my training and test data, ı imported the keras library as seen below
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
But the prcocess did not finished normally.I tookthe same error-> cannnot import name 'LayerNormalization' from 'tensorflow.python.keras.layers.normalization'
I am using the following versions Spyder 4.2.5 tensorflow 2.7
Please create a new virtual environment in ananconda to install TensorFlow:
conda create -n tf tensorflow #"tf" is the name for your TensorFlow environment
conda activate tf # to activate the virtual environment
pip install tensorflow # install tensorlfow in that environment
Select the same "tf" environment in anaconda navigator and install Spyder to launch and type below code to check if TensorFlow installed properly:
import tensorflow as tf
Now please try again executing your code in this Spyder IDE.
I installed tensorflow-gpu in anaconda3.
The steps I followed are:
conda create -n tensorflow pip python=3.6
source activate tensorflow
pip install tensorflow_gpu-1.8.0-cp36-cp36m-linux_x86_64.whl
After these steps, I find that if I use the python and ipython in anaconda3/bin, I can't import tensorflow (no module named tensorflow)
But If I activate the environment of tensorflow or I use the python and ipython in anaconda3/env/tensorflow/bin, I can import tensorflow.
And there is also no directory for tensorflow inanaconda3/lib/python3.6/site-package
Anyone knows why?
You created a conda environment and installed Tensorflow to that environment. Therefore you can only use Tensorflow inside that environment.
If you wish to use Tensorflow outside of an environment then don't activate the environment you created and just pip install Tensorflow.
I have installed Anaconda with jupyter notebook in /home/serg/anaconda/bin and installed tensoflow in ./.local/lib/python3.5/site-packages/tensorflow. My operation system is Ubuntu 16.04.
Is it possible to use tensorflow in jupyter notebook via changing some configuration in anaconda or jupyter?
P.S.: I know it is possible for most python IDE, but I need to do it with jupyter notebook in anaconda.
Looks like you may have installed stuff in the wrong order.
I run TensorFlow in Jupyter notebook all the time, I don't get your issue? If you have installed Anaconda and it is active eg when you type python, you get the Anaconda version of python, you just install TensorFlow with Pip (following instructions at TF.. ) and the fire up jupyter notebook do your imports including TF and you should be off and going, nothing special required. If you did it in the wrong order, eg TF then Anaconda just make sure that Anaconda is your default interpeter (as above) and re-install TF with pip. If that does not seem to fix whatever issue you are having, post more info...
post your notebook info that tries to import TF?
I understood my problem: just used anaconda promts and installed tensoflow right here. Then I run jupyter notebook in anaconda promts and imported tensorflow.
I have installed tensorflow with anaconda in Windows, but I can't import tensorflow in spyder IDE?
The reason Spyder is unable to import Tensorflow is that Anaconda does not store the tensorflow package in the same environment.
One solution is to create a new separate environment in Anaconda dedicated to TensorFlow and containing Python with its own Spyder and then install tensorflow into that environment