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.
Related
I have just had to reset Windows 10 to factory settings. I have re-installed Anaconda/Spyder and I am having problems installing Keras and TensorFlow at the moment.
I have attempted both pip and conda installations of TensorFlow but I am getting the below stack trace when I just attempt to run "import tensorflow as tf", or "import tf" (I wasn't sure which was correct)
To install tensorflow, I ran the below commands in the base Anaconda prompt as admin.
conda create -n tf tensorflow
conda activate tf
When I run the above import, I get the below error.
runfile('C:/Users/username/.spyder-py3/untitled0.py', wdir='C:/Users/username/.spyder-py3')
Traceback (most recent call last):
File "C:\Users\username.spyder-py3\untitled0.py", line 15, in
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
I have tried re-installing Anaconda, etc to no avail.
Anybody know what is wrong here?
Follow these instructions to install Tensorflow on Spyder
#Create environment
conda create -n tf python=3.7 anaconda
#Activate environment
activate tf
#Install Spyder
conda install spyder
#Install Tensorflow
conda install tensorflow
#Test installation
import tensorflow as tf
I installed tensorflow 2.0 from source, following the official instructions: https://www.tensorflow.org/install/source
It works when I access from python console (Outside of tensorflow folder), I want to get access from Jupyter notebook.
I copied tensorflow's folder to:
/home/kati/anaconda3/pkgs/tensorflow
but still not working
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-d6579f534729> in <module>
----> 1 import tensorflow
ModuleNotFoundError: No module named 'tensorflow'
System Info
Ubuntu 18.04.3
jupyter core : 4.5.0
jupyter-notebook : 6.0.0
Here are the steps:
Download Anaconda
Create a virtual environment and activate it
Install K̵e̵r̵a̵s̵ ̵a̵n̵d̵ TensorFlow etc.
Launch Jupyter Notebook
Since you already have Jupyter Notebook, you will need to create an env variable, install tensorflow and keras. Commands are mentioned below:
update conda in your default environment
$ conda upgrade --all
create a new environment with conda
$ conda create -n [my-env-name] python=[python-version]
activate the environment you created
$ source activate [my-env-name]
install pip in the virtual environment
$ conda install pip
install Tensorflow CPU version
$ pip3 install --upgrade tensorflow # for python 3.*
install Keras (Note: please install TensorFlow first)
$ pip install Keras
remove an environment
$ conda env remove --name [my-env-name]
Install pip package and then you can just use "pip install [package name]" command to install any package easily.
Did you start running jupyter notebook from the virtual environment which you installed tensorflow?
Also you don't need to copy tensorflow to anaconda3 folder it's better to install by using pip or anconda navigator.
pip install tensorflow
Reference:
https://pypi.org/project/tensorflow/
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 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
After having installed tensorflow on Ubuntu 16.0 on AWS,
by using :
conda install -c conda-forge tensorflow=1.2.1
When typing on terminal SSH :
ipython
import tensorflow as tf
tf.__version__
It returns 1.2.1 and everything is fine.
But, when this code is run on Jupyter Ipython notebook
launched from same python install (anaconda),
I got this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-b6f7b46cc0dd> in <module>()
1 import tensorflow as tf
----> 2 tf.__version__
AttributeError: module 'tensorflow' has no attribute '__version__'
Don't understand how this error can come over since the python distribution
is the same.
Is there a way to check the install of Tensorflow ?
EDIT:
This post https://github.com/tensorflow/tensorflow/issues/3369
shows it might be related to sudo access to some folders.... when installed.
TBD