Using TensorFlow backend. Error importing tensorflow - python

I've installed and imported tensorflow before (https://github.com/ankur715/MOOCs/blob/master/pythonprogramming/ds_tf_keras_tutorial.ipynb), but Anaconda on my Windows went haywire starting this week.
It wasn't loading the Jupyter localhost after several tries/times, so I uninstalled it and reinstalled it. Then realized that Python 3.7 is what didn't allow tensorflow. I downgraded to Python 3.5, checked version of tensorflow which is 0.12.0.
I think it wasn't working because of Python 3.7 earlier, and now tensorflow is 0.12.0. How do I upgrade to tensowflow 1.12.0, to see if that'll solve it?

It is better to remove and install:
conda uninstall tensorflow
conda install -c conda-forge tensorflow=1.12.0
Look here.

Related

jupyter runs an old pytorch version

I have elementary knowledge on package managers, so forgive me if my question is phrased badly.
I am using miniconda as a package manager. I have python 3.8 installed, and I use jupyter lab to run ipython kernels.
My issue is that when import torch then the version 1.7.1 is loaded to the notebook, however, when I look at conda list I see that version 1.8.1 of torch is installed.
When I try to update using conda update --all and conda update pytorch nothing is being installed.
So
I don't know why pytorch is not updated to the new version of 1.9.
I don't know why an older version 1.7.1 is loaded to my jupyter notebook.
would love to get some help!
I am not sure exactly what solved it, but:
I updated homebrew which required me to install some command line tools of x-code, and then I managed to install pytorch again using
conda install pytorch torchvision -c pytorch.
Now the proper version is loaded when I use jupyter.

jupyter ModuleNotFoundError: No module named Tensorflow or keras

I cannot seem to import Tensorflow or keras.
I have windows 10 computer
I have python 3.8.5
I installed the following using command pip3 install XXXXXXXXXX
1.matplotlib
2.pandas
3.numpy
4.Tensorflow
5.keras
in that order
i have no problem importing matplotlib, pandas or numpy.
but when I try to import tensorflow or keras, it cannot find the module (see screenshot provided)
i also checked in cmd to ensure i have them installed (see screenshot)
FYI, I installed python in drive F: and windows is installed in drive C:
is there a reason why I can import pandas, and not tensorflow or keras?
any form of help would be highly appreciated!
screenshot on jupyter error:
what version of tensorflow do you want to install? My experience is to use Anaconda onda terminal to install tensorflow. First install tensorflow 2.1 using conda.Conda automatically installs cudnn 7.6.5 and CUDA Toolkit 10.1.243. These are compatible with tensorflow 2.2. Then use pip to install tensorflow 2.2 as shown below
pip install tensorflow ==2.2.0
Conda at this time can only install tensorflow up to 2.1 that is why you have to use pip. pip does not automatically install cudnn or the Cuda toolkit but you already have them installed when you install version 2.1 with Conda. Otherwise you would have to go through a more complicated process to manually install cudnn and the toolkit. Some people have reported problems using python 3.8 with tensorflow. If you run into that create as seperate environment and install python 3.7, tensorflow 2.1 using conda, then install tensorflow 2.2 using pip.

Cannot install TensorFlow 1.x

I am trying to install Tensorflow 1.14 for a package that I am trying to use. I tried:
pip3 uninstall tensorflow
Then I tried to install Tensorflow 1.14 using:
pip3 install tensorflow==1.14
and I get the following error
ERROR: Could not find a version that satisfies the requirement tensorflow==1.14 (from versions: 2.2.0rc3, 2.2.0rc4, 2.2.0, 2.3.0rc0, 2.3.0rc1, 2.3.0rc2) ERROR: No matching distribution found for tensorflow==1.14
I also tried making a new virtual env and tried the following commands but it didn't work. Is there any way to install Tensorflow 1?
What I've found on discourse:
You just need to make sure you’re using Python 3.5, 3.6 or 3.7. TensorFlow 1.15 does not support Python 3.8
It works for me to install 1.x tensorflow with the following command:
pip3 install https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.14.0-py3-none-any.whl
Try installing the final version of TensorFlow 1.15 using,
pip install tensorflow==1.15
Make sure that you are using a python3 virtual environment and Python version is 3.6 or above.
Or you may use Conda environment and install using
conda install -c conda-forge tensorflow=1.15
On top of what being said (i.e. the version), be sure that it is 64-bits version because Tensorflow is not working with Python 32 bits (or at least the recent versions).
You can check your version by typing python in the command line and check what appears.
For example, this is for 32 bits
and for 64bits
I faced the same issue while installing tensorflow version 1.14.0. The best solution i tried is:
Note that your Python version is 3.7.8
Steps:
Open python 3.7.8 script folder C:\Users\mypc\AppData\Local\Programs\Python\Python37\Scripts folder and type "cmd" in above bar, which opens it in the command prompt.
To install tensorflow-1.14.0 type : pip install tensorflow==1.14.0
To install keras-2.2.4 type : pip install keras==2.2.4
From this issue on the Tensorflow Github titled Tensorflow 1.x not available for python 3.8:
Saduf2019: TensorFlow 1.x even 2.1 does not support Python 3.8
mihaimaruseac: We don't add new versions of Python for old releases. If you want to use TF 1.15, you have to use Python 3.7 or lower. If you want to use Python 3.8 you have to use TF 2.2 or newer.
Sounds like support for newer versions of Python > 3.7 won't be available for any tensorflow 1.x < 1.15.

Force Anaconda to install tensorflow 1.14

Now, the official TensorFlow on Anaconda is 2.0. My question is how to force Anaconda to install an earlier version of TensorFlow instead. So, for example, I would like Anaconda to install TensorFlow 1.14 as plenty of my projects are depending on this version.
You can force installing a certain version of any package found on Anaconda using simply an = operator with the package version attached to it.
So, if you want to install tensorflow 1.14, you can run the following command:
conda install -c conda-forge tensorflow=1.14
You can replace 1.14 with any other versions. To see the available versions of tensorflow on Anaconda, you can run:
conda search tensorflow
first find the python version of tensorflow==1.14.0, then find the Anaconda version by python version.
e.g. tensorflow 1.14.0 can work well on python36, and Anaconda 3.5.1 has python36. So install the Anaconda 3.5.1, then install tensorflow==1.14.0 by pip

Tensorflow install fails with "compiletime version 3.5 of module does not match runtime version 3.6"

I tried installing from pip:
pip3 install --user --no-cache https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.4.0-cp36-cp36m-linux_x86_64.whl
Then tried importing and got:
Using TensorFlow backend.
/usr/lib64/python3.6/importlib/_bootstrap.py:205: RuntimeWarning:
compiletime version 3.5 of module
'tensorflow.python.framework.fast_tensor_util' does not match runtime
version 3.6
return f(*args, **kwds)
2017-11-10 09:35:01.206112: I
tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports
instructions that this TensorFlow binary was not compiled to use: SSE4.1
SSE4.2 AVX
Questions:
I don't understand why the wheel says 3.6, but I get the warning about 3.5
I want to compile to optimize for my cpu, so can I use pip to install from source rather than from binary wheel?
RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
This is a known issue, which is got prioritized and likely to be fixed soon. Right now the workaround is to use python 3.5.
UPDATE:
The issue has been fixed in the nightly tensorflow builds: "tf-nightly and tf-nightly-gpu now has a python3.6 binary built from scratch for Linux."
I.e., the following command should work with python 3.6:
# tf-nightly or tf-nightly-gpu
pip3 install tf-nightly
Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX
This warning comes from the fact that the default tensorflow distributions are compiled without CPU extensions support (more on this here). If you want to get a CPU optimized tensorflow package, your only option is to build it yourself. It's a bit tedious, but absolutely doable. The build will produce the wheel file, which you can install with just
pip3 install /path/to/the/tensorflow.whl
But if you just want to suppress the warning, this will do:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
I got the same issue and I was able to solve it by installing 1.3 version rather than using 1.4 of tensorflow. Use the following command to do so.
pip3 install tensorflow==1.3.0
I encountered the same problem and I fixed it by:
pip install --ignore-installed tensorflow
The problem occurred because I complied a local version of tensorflow (to enable some CPU features) with python 3.5 earlier. I installed python 3.6 recently and the new tensorlfow already supported those CPU features, so I just installed the official version.
Update:
After some update of tensorflow the approach above doesn't work any more.
Another workaround is using virtual environment such as anaconda to create a python3.5 environment:
conda create -n py35 python=3.5
source activate py35
pip install tensorflow
To work with ipython or jupyter notebook, be sure to install ipykernel inside the virtual environment:
pip install ipykernel
Just install 1.3 version of tensorflow. Problem solved.
pip install tensorflow==1.3.0
solution 1.
the way I solved this is by downgrading to the latest python3.5, go to python.org download the latest Python3.5, install it and then use normalpip3 install tensorflow this should be able to fix the issue if not try the second solution.
solution 2(also you need to downgrade from python3.6 to python3.5
I used Pycharm to solve the issue, I created a project inside the pycharm editor then I changed the Project Interpreter from python3.6 to python3.5, to do this as well go to File > Preferences search for Project Interpreter, and from the drop-down menu change from python3.6 to python3.5
hit Apply wait for the operation to finish
and then in the same window using the + icon
A window will appear that will let you search and install python libraries easily without using pip, in our case we want tensorflow, so just search tensorflow, select tensorflow on search result and click Install Package this will install the package
and voila you're ready to roll, now you got tensorflow installed on your python3.5, keep that in mind.
For now you can use python version less than 3.6.x because now Tensorflow 1.4.0 is not working properly with python 3.6.x. It will surly work.
This issue was resolved on ubuntu 17.10 by running
$ conda install tensorflow
i use tensorflow 1.4.0, meet the same problem. but you can use tensorflow 1.6.0, now.

Categories