I'm running a code which requires keras version 1.2.0 and tensorflow version 1.1.0.
I'm using Jupyter notebook and I created an environment for all the dependencies.
However, I mistakenly installed both libraries again through pip command which installed the latest versions.
I closed the notebook, opened it again and created the environment once again so the older version of both libraries were installed again.
But when I run keras.__version___ command, it shows 2.4.3, which i do not want.
I also ran conda remove keras --force and pip uninstall keras, but it's still showing the latest version.
The code is only compatible with the older version. Please help.
It's probably because it is getting uninstalled on a different environment. Identify which python and pip executable you are using by running the following commands:
$ which pip
$ which python
These two commands will give out the path of the executable from which we can determine the environment. If it is different from what you were using you can try installing to the desired environment by running:
/path/to/desired/pip uninstall keras
/path/to/desired/pip install keras==1.2.0
Hi
in jupyter notebook, when i tried to import tensorflow like below, i got an error of ModuleNotFoundError: No module named 'tensorflow'. Then, I opened anaconda prompt and trying to install tensorflow in anaconda and it failed many times and here is the error message. Could you please help me what is the problem? Thanks
import tensorflow as tf
ok, so i tried to downgrade python from 3.8 to 3.6 and i still got an error at the end, could anyone help pls? Thanks
EnvironmentNotWritableError: The current user does not have write permissions to the target environment.
environment location: C:\ProgramData\Anaconda3
According to TensorFlow docs, tf is compatible with python 3.5, 3.6, 3.7 or 3.8
and also python 3 64bit release is a must, so it's maybe worth to check if you don't try to install tf accidentally on 32bit version of python.
https://www.tensorflow.org/install/pip#windows
import sys
print(sys.version)
I installed tf according to Anaconda docs:
create fresh env,
activate it,
and install tf:
conda create -n myproject tensorflow
conda activate myproject
conda install tensorflow
I can see that conda automatically selected python version 3.7.9
verify:
import tensorflow as tf
tf.version.VERSION
your python version is not compatible with this version of tensorflow. you are using python 3.8 downgrade python to either 3.5, 3.6 or 3.7. downgrading python should solve your issue.
I'm using anaconda ver 3, and I have installed python as well separately from anaconda. I installed python ver 2.7 and ver 3.6 from python website.
Now, I have installed keras from anaconda command prompt by using conda install keras. However, when I open jupyter notebook and write :
import keras
it says :
no module named keras
I also tried importing tensorflow but it gave me the same error
As far as i know, keras is a version of tensorflow. You should try installing tensorflow instead and then run
import tensorflow as tf
tf.__version__
if you get '2.1.0' or any 2., you should be all set!
EDIT1: Keras is part of tensorflow not a version (as pointed out in the comments).
EDIT2: The link below gives good details on environments activation/creation.
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
Okay so what I did is first updated anaconda by using :
conda update conda
and then I installed python :
conda install python=3.7
and finally I installed keras again :
conda install keras
And now I can import both packages of keras and tenserflow
I am trying to install Tensorflow on a Windows 7 laptop in order to use jupyter notebook to play around with the object detection notebook in Github. I am facing this error:
ImportError Traceback (most recent call
last) in ()
4 import sys
5 import tarfile
----> 6 import tensorflow as tf
7 import zipfile
8
ImportError: No module named tensorflow
I am getting the above error when I start the Jupyter Notebook from inside the Conda environment in Windows 7. I have installed Python 3.5.4 & within conda environment, tensorflow as well.
I am also getting ... not recognized as an internal/external... for $ command while giving $ python and sometimes also for pip3 I have included several file paths in Environment Variables. Can you please suggest me what to do. I am using the Conda env as I feel I have a problem in having Windows Service Pack 1.
Make sure your Tensorflow folder is somewhere that the environment will look, such as [Python install directory]/Lib/Site-packages
If you are using Anaconda to manage your installation, be aware that it is community supported and not officially supported by Google. Google has a detailed guide on how to install Tensorflow on Windows as well as how to validate the installation. Follow their steps carefully and be aware you may need to start the process over if you miss a step.
1) Make sure you start with a clean Conda Environment for Tensorflow. You will need to specifiy Python version 3.5. You can do this by running the command,
C:> conda create -n tensorflow python=3.5
2) Once the new Conda environmnet is created, activate it. This step is commonly overlooked.
C:> activate tensorflow
(tensorflow)C:> # The Conda environment may appear before the drive letter
3) With the Tensorflow environment active, issue the pip command to install the appropriate Tensorflow version. To keep things simple, I assume you will be installing the CPU version. If you need the GPU version, refer to the Google guide since there are other things you will need to do in order to set up the NVIDIA drivers.
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow
Note the flags included on the pip install command.
To make sure that Tensorflow is installed properly, validate the installation. Do this by double checking that the Tensorflow Conda environment is active and starting a python console. Once the console is running type the following sample program, suggested by Google's guide.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
If you are new to Tensorflow, this code may not make sense. What it does is import the Tensorflow library, assign a variable called "hello" to a Tensorflow constant tensor. Tensorflow is a library designed to operate on Tensor data objects. The next line initiates a Tensorflow session which loads all the data objects. The final line prints the output of Session.run() on the hello constant object. If everything is set up correctly you should see
Hello, TensorFlow!
output on the console. If you don't, check to common installation issues included in Google's Tensorflow install guide.
I have some imports in my jupyter notebook and among them is tensorflow:
ImportError Traceback (most recent call last)
<ipython-input-2-482704985f85> in <module>()
4 import numpy as np
5 import six.moves.copyreg as copyreg
----> 6 import tensorflow as tf
7 from six.moves import cPickle as pickle
8 from six.moves import range
ImportError: No module named tensorflow
I have it on my computer, in a special enviroment and all connected stuff also:
Requirement already satisfied (use --upgrade to upgrade): tensorflow in /Users/mac/anaconda/envs/tensorflow/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): six>=1.10.0 in /Users/mac/anaconda/envs/tensorflow/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied (use --upgrade to upgrade): protobuf==3.0.0b2 in /Users/mac/anaconda/envs/tensorflow/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.10.1 in /Users/mac/anaconda/envs/tensorflow/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied (use --upgrade to upgrade): wheel in /Users/mac/anaconda/envs/tensorflow/lib/python2.7/site-packages (from tensorflow)
Requirement already satisfied (use --upgrade to upgrade): setuptools in ./setuptools-23.0.0-py2.7.egg (from protobuf==3.0.0b2->tensorflow)
I can import tensorflow on my computer:
>>> import tensorflow as tf
>>>
So I'm confused why this is another situation in notebook?
If you installed a TensorFlow as it said in official documentation: https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html#overview
I mean creating an environment called tensorflow and tested your installation in python, but TensorFlow can not be imported in jupyter, you have to install jupyter in your tensorflow environment too:
conda install jupyter notebook
After that I run a jupyter and it can import TensorFlow too:
jupyter notebook
Jupyter runs under the conda environment where as your tensorflow install lives outside conda. In order to install tensorflow under the conda virtual environment run the following command in your terminal:
conda install -c conda-forge tensorflow
I had the same problem, and solved it by looking at the output of:
jupyter kernelspec list
which outputs the kernel information:
python2 /Users/Username/Library/Jupyter/kernels/python2
python3 /Users/Username/Library/Jupyter/kernels/python3
Notice that the path points to the Jupyter kernel for the user. To use it within the the Anaconda environment, it needs to point to the conda env you are using, and look something like Anaconda3\envs\Env_Name\share\jupyter\kernels\python3.
So, to remove the Jupyter kernelspec, just use:
jupyter kernelspec remove python3
or jupyter kernelspec remove python2 if you're using python 2
Now, the output of jupyter kernelspec list should point to the correct kernel.
See https://github.com/jupyter/notebook/issues/397 for more information about this.
Conda environment fetches the tensorflow package from the main system site-packages.
Step 1: Just deactivate conda environment
conda deactivate
pip install tensorflow
Step 2: Switch back to conda environment
conda activate YOUR_ENV_NAME
jupyter notebook
Step 3: Run the cell with import tensorflow you should be able to import.
Thanks
I also had the same problem for a long time. I wanted to import tensorflow inside the jupyter notebook within windows 10. I followed all the instructions and commands that were suggested and it was not working from the command prompt. Finally, I tried this command with the Anaconda Prompt and it worked successfully. If you are using jupyter notebook within Anaconda then go goto the windows search terminal and type "Anaconda Prompt" and inside it type following command, It will install the tensorflow inside the jupyter notebook.
conda install -c conda-forge tensorflow
the problem may when the Jupyter notebook may launching from the default but for able to import tensorflow and keras libraries so you have to install jupyter notebook like what you have installed the libraries
pip install jupyter
Run python -m ipykernel install --user --name <Environment_Name>. This should add your environment to the jupyter kernel list.
Change the kernel using Kernel->Change Kernel option or New-><Environment_Name>.
Note : Replace <Environment_Name> with the actual name of the environment.
run this command which will install tensorflow inside conda
conda install -c conda-forge tensorflow
This is what I did to fix this issue -
I installed tensorflow for windows by using below link -
https://www.tensorflow.org/install/install_windows
Once done - I activated tensorflow by using below command -
C:> activate tensorflow
(tensorflow)C:> # Your prompt should change
Once done I ran below command -
(tensorflow)C:> conda install notebook
Fetching package metadata ...........
Solving package specifications: .
Package plan for installation in environment
The following NEW packages will be INSTALLED:
bleach: 1.5.0-py35_0
colorama: 0.3.9-py35_0
decorator: 4.1.2-py35_0
entrypoints: 0.2.3-py35_0
html5lib: 0.9999999-py35_0
ipykernel: 4.6.1-py35_0
----
---
jupyter_client 100% |###############################| Time: 0:00:00 6.77 MB/s
nbformat-4.4.0 100% |###############################| Time: 0:00:00 8.10 MB/s
ipykernel-4.6. 100% |###############################| Time: 0:00:00 9.54 MB/s
nbconvert-5.2. 100% |###############################| Time: 0:00:00 9.59 MB/s
notebook-5.0.0 100% |###############################| Time: 0:00:00 8.24 MB/s
Once done I ran command
(tensorflow)C:>jupyter notebook
It opened new Juypter window and able to Run fine -
import tensorflow as tf
I was able to load tensorflow in Jupyter notebook on Windows by: first do conda create tensorflow install, then activate tensorflow at the command prompt , then execute "Jupyter notebook" from command line.
Tensorflow imports at the notebook with no error. However, I was unable to import "Pandas" &"Matplotlib, ....etc"
As suggested by #Jörg, if you have more than one kernel spec. You have to see the path it points to. In my case, it is actually the path that was to be corrected.
When I created TensorFlow virtual env, the spec had the entry for python which was pointing to base env. Thus by changing W:\\miniconda\\python.exe to W:\\miniconda\\envs\\tensorflow\\python.exe solved the problem.
So it is worth looking at your kernel spec. Delete that is not needed and keep those you want. Then look inside the JSON files where the path is given and change if needs be. I hope it helps.
There are two ways to fix this issue.
The foremost way is to create a new virtual environment and install all dependencies like jupyter notebook, tensorflow etc.
conda install jupyter notebook
conda install -c conda-forge tensorflow
The other way around is to install tensorflow in the current environment (base or any activated environment).
conda install -c conda-forge tensorflow
Note: It is advisable to create a new virtual environment for every new project. The details how to create and manage virtual environment using conda can be find here:
https://conda.io/docs/user-guide/tasks/manage-environments.html
Probably there is a problem with the TensorFlow in your environment.
In my case, After installing some libs, my TensorFlow stopped working.
So I installed TensorFlow again using pip. like so:
just run
pip install tensorflow
then I re-imported it into my jupyter notebook as :
import tensorflow as ft
In case you want to install jupyter and base libs try this:
pip install jupyter tensorflow keras numpy scipy ipython pandas matplotlib sympy nose
Other supported libraries are necessary to install with TensorFlow.Make sure if these libraries are installed:
numpy
scipy
jupyter
matplolib
pillow
scikit-learn
tensorflow-addons,
tensorflow.contrib
This worked for me. I followed this: https://www.pythonpool.com/no-module-named-tensorflow-error-solved/
TensorFlow package doesn't come by default with the root environment in Jupyter, to install it do the following :
Close Jupyter Notebook.
Open Anaconda Navigator (In windows : you can find it using the search bar)
On the sidebar, click on the Environments tab (by default you are using the root env).
You can see the installed packages, on the top switch to not-installed packages and search for tensorflow, if it doesn't show, click on Update index and it will be displayed.
The installation takes some time
If you have installed TensorFlow globally then this issue should not be occurring. As you are saying you have installed it, maybe you did it in a virtual environment.
Some background:
By default, Jupyter will open with a global python interpreter kernel.
Possible solutions:
Change your jupyter notebook kernel to your virtual environment kernel. Please check here to see how to create a kernel out of your virtual environment.
Troubleshooting:
If the above solution dint work lets do some troubleshooting. When you add your new kernel to jupyter you might have got output like below
Installed kernelspec thesis-venv in C:\Users\vishnunaik\AppData\Roaming\jupyter\kernels\venv
Check the file kernel.json in this path, which might look something like below
{
"argv": [
"C:\\Users\\vishnunaik\\Desktop\\Demo\\CodeBase\\venv\\Scripts\\python.exe",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "thesis-venv",
"language": "python",
"metadata": {
"debugger": true
}
}
Check the path to the python.exe is rightly pointing to your virtual environment python version or not. If not then update it accordingly.
Now you should be able to use a virtual environment in your jupyter notebook. If your kernel takes a lot of time to respond see jupyter notebook server logs, sometimes you might get output like this
[I 21:58:38.444 NotebookApp] Kernel started: adbd5551-cca3-4dad-a93f-974d7d25d53b, name: thesis-venv C:\\Users\\vishnunaik\\Desktop\\Demo\\CodeBase\\venv\\Scripts\\python.exe: No module named ipykernel_launcher
This means your virtual environment doesnot have ipykernel installed. So install it in your virtual environment using below command.
pip install ipykernel
Now you have done everything possible, so I hope this will solve your issue.