I've been trying to install keras and tensorflow for Jupyter-lab (python).
I first tried with pip, but the notebook stopped functioning everytime I imported keras.
After some research on different feeds, I decided to uninstall it with pip and try to reinstall it with anaconda3.
Then, there was a path issue installing tensorflow with the conda command. So I researched more and wrote this in the terminal :
export PATH="/home/myname/anaconda3/bin:$PATH"
I created another environment and could install tensorflow with (same for keras) :
conda activate myenv
conda install tensorflow
I came back on the local JupyterLab and imported keras. But it couldn't find the module named keras. I tried again with pip :
!pip install keras
import keras
And got the same :
Requirement already satisfied: keras in /home/myname/.conda/envs/myenv/lib/python3.9/site-packages (2.9.0)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [6], in <cell line: 10>()
---> 10 import keras
ModuleNotFoundError: No module named 'keras'
Is it a path problem ? How can I solve it ? I don't understand how it can find it, but not import it correctly.
Thank you for your help !
After creating the virtual environment(myenv) in conda, open a new jupyter notebook in the same environment and you need to install TensorFlow in that environmnet using the below code:
!pip install tensorflow
import tensorflow as tf
tf.__version__
Now you can access the Keras from TensorFlow as below:
from tensorflow import keras
keras.__version__
I am working on pose estimation using OpenPose. For that I installed TensorFlow GPU and installed all the requirements including CUDA development kit.
While running the Python script:
C:\Users\abhi\Anaconda3\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py, I encountered the following error:
ImportError: cannot import name '_pywrap_utils' from
'tensorflow.python'
(C:\Users\abhi\Anaconda3\lib\site-packages\tensorflow\python__init__.py)
I tried searching for _pywrap_utils file but there was no such file.
Try pip3 install pywrap and pip3 install tensorflow pywrap utils should be included with tensorflow. If it is not found, that means TF was not installed correctly.
then i type import tflearn i got the error below, i follow the guide here: https://www.youtube.com/watch?v=ViO56ASqeks
what can i use tflearn, or shall i use another code?
i got the error below.
import tflearn
File "/usr/local/lib/python3.5/dist-packages/tflearn/__init__.py", line 4, in <module>
from . import config
File "/usr/local/lib/python3.5/dist-packages/tflearn/config.py", line 5, in <module>
from .variables import variable
File "/usr/local/lib/python3.5/dist-packages/tflearn/variables.py", line 7, in <module>
from tensorflow.contrib.framework.python.ops import add_arg_scope as contrib_add_arg_scope
ImportError: No module named 'tensorflow.contrib.framework
can someone help me ?
20/08-2019: Edit 20.35
pip list:
tensorflow 2.0.0rc0
I had a similar problem and I solved it by:-
1) upgrading python to 3.6
2) pip uninstall tflearn
3) pip install git+https://github.com/tflearn/tflearn.git
4) As suggested in another solution tensorflow 2.0.0 does not support tflearn so I installed tensorflow==1.14.0
I found the solution here:-
Issue Link/
If you use an conda environment (and not only, but I advise you to use it), then the solution will be to use a lower version of tensorflow pip uninstall tensorflow pip install tensorflow==1.14.0.
And it is possible to use the script to fix all errors(i used it before downgrade tf):
tf_upgrade_v2 \
--intree my_project/ \
--outtree my_project_v2/ \
--reportfile report.txt
It works for me
You need to have tensorflow installed before you can use tflearn.
From the tflearn github page:
TensorFlow Installation
TFLearn requires Tensorflow (version 1.0+) to be installed.
To install tensorflow:
pip install tensorflow
The tutorial that you are watching uses tensorflow version 0.9 or something, current version is 2.0. The tutorial is 3 years old. You should watch updated video.
However, you can try.
pip install tensorflow==1.0
pip install tflearn
if you're using a virtual environment, make sure you have activated it.
You can use keras instead of tflearn.
tensorflow.contrib is being removed in version 2.0, you therefore need version <= 1.14 to operate tflearn (see here).
I am getting an import error when trying to import the Keras module Nadam:
>>> from keras.optimizers import Nadam
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name Nadam
I can import and use SGD, Adam, etc, just not this optimizer. Any help appreciated.
I installed Keras using:
git clone https://github.com/fchollet/keras.git
sudo python2.7 setup.py install
I have just found that, if I try to import it using the shell immediately after installation, the Nadam import works. But Nadam won't import in my script. So it's a path issue?
If you can import something in one place but not another, it's definitely an issue with the import system. So, carefully check the relevant variables (sys.path, environment variable PYTHONPATH) and where the modules in each case are being imported from (sys.modules).
For a more in-depth reading, I direct you to the Python import system docs and an overview of common traps in the system.
You may also have an old version of Keras installed somewhere: Nadam is a fairly recent addition (2016-05), so this may be the cause for the "can import other optimizers but not this one" behaviour.
It could happen if you're using other version of python. Let's say, you have installed python globally with version 2.7.x, but when running your script, you're using python 3.x. In this case even you'll run python shell, you'll be able to import it, but when running concrete script which uses other version of python it wouldn't be possible.
Seems as if your keras package is not the latest version. Update your keras package by
sudo -H pip3 install git+https://github.com/fchollet/keras.git --upgrade
or
sudo -H pip3 install git+https://github.com/fchollet/keras.git --upgrade
I've been trying to use tensorflow for two days now installing and reinstalling it over and over again in python2.7 and 3.4. No matter what I do, I get this error message when trying to use tensorflow.placeholder()
It's very boilerplate code:
tf_in = tf.placeholder("float", [None, A]) # Features
No matter what I do I always get the trace back:
Traceback (most recent call last):
File "/home/willim/PycharmProjects/tensorflow/tensorflow.py", line 2, in <module>
import tensorflow as tf
File "/home/willim/PycharmProjects/tensorflow/tensorflow.py", line 53, in <module>
tf_in = tf.placeholder("float", [None, A]) # Features
AttributeError: 'module' object has no attribute 'placeholder'
Anyone know how I can fix this?
If you have this error after an upgrade to TensorFlow 2.0, you can still use 1.X API by replacing:
import tensorflow as tf
by
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
Solution: Do not use "tensorflow" as your filename.
Notice that you use tensorflow.py as your filename. And I guess you write code like:
import tensorflow as tf
Then you are actually importing the script file "tensorflow.py" that is under your current working directory, rather than the "real" tensorflow module from Google.
Here is the order in which a module will be searched when importing:
The directory containing the input script (or the current directory when no file is specified).
PYTHONPATH (a list of directory names,
with the same syntax as the shell variable PATH).
The installation-dependent default.
It happened to me too. I had tensorflow and it was working pretty well, but when I install tensorflow-gpu along side the previous tensorflow this error arose then I did these 3 steps and it started working with no problem:
I removed tensorflow-gpu, tensorflow, tensorflow-base packages from Anaconda. Using.
conda remove tensorflow-gpu tensorflow tensorflow-base
re-installed tensorflow. Using
conda install tensorflow
Instead of tf.placeholder(shape=[None, 2], dtype=tf.float32) use something like
tf.compat.v1.placeholder(shape=[None, 2], dtype=tf.float32) if you don't want to disable v2 completely.
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
works.
I am using Python 3.7 and tensorflow 2.0.
It appears that .placeholder() , .reset_default_graph() , and others were removed with version 2. I ran into this issue using Docker image: tensorflow/tensorflow:latest-gpu-py3 which automatically pulls the latest version. I was working in 1.13.1 and was 'upgraded to 2' automatically and started getting the error messages. I fixed this by being more specific with my image: tensorflow/tensorflow:1.13.1-gpu-py3.
More info can be found here: https://www.tensorflow.org/alpha/guide/effective_tf2
Avoid using the below striked out statement in tensorflow=2.0
i̶m̶p̶o̶r̶t̶ ̶t̶e̶n̶s̶o̶r̶f̶l̶o̶w̶ ̶a̶s̶ ̶t̶f̶ ̶x̶ ̶=̶ ̶t̶f̶.̶p̶l̶a̶c̶e̶h̶o̶l̶d̶e̶r̶(̶s̶h̶a̶p̶e̶=̶[̶N̶o̶n̶e̶,̶ ̶2̶]̶,̶ ̶d̶t̶y̶p̶e̶=̶t̶f̶.̶f̶l̶o̶a̶t̶3̶2̶)̶
You can disable the v2 behavior by using the following code
This one is perfectly working for me.
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
x = tf.placeholder(shape=[None, 2], dtype=tf.float32)
I also got the same error. May be because of the version of tensorflow.
After installing tensorflow 1.4.0, I got relief from the error.
pip install tensorflow==1.4.0
If you are using TensorFlow 2.0, then some code developed for tf 1.x may not code work. Either you can follow the link : https://www.tensorflow.org/guide/migrate
or you can install a previous version of tf by
pip3 install tensorflow==version
Import the old version of tensorflow instead of the new version
[https://inneka.com/ml/tf/tensorflow-module-object-has-no-attribute-placeholder/][1]
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
You need to use the keras model with tensorflow 2, as here
import tensorflow as tf
from tensorflow.python.keras.layers import Input, Embedding, Dot, Reshape, Dense
from tensorflow.python.keras.models import Model
Recent version 2.0 does not support placeholder.
I uninstalled 2.0 using command: conda remove tensorflow.
then I installed 1.15.0 using command: conda install -c conda-forge tensorflow=1.15.0.
1.15 is latest in version 1 series. You can change as per you wish and requirement.
For seeing all version, use command: conda search tensorflow.
It worked for Anaconda3 in Windows.
Try this:
pip install tensorflow==1.14
or this (if you have GPU):
pip install tensorflow-gpu==1.14
Please take a look at the Migrate your TensorFlow 1 code to TensorFlow 2.
These codes:
import tensorflow as tf
tf_in = tf.placeholder("float", [None, A]) # Features
need to be migrated in TensorFlow 2 as below:
import tensorflow as tf
import tensorflow.compat.v1 as v1
tf_in = vi.placeholder("float", [None, A]) # Features
If you get this on tensorflow 2.0.0+, it's very likely because the code isn't compatible with the newer version of tensorflow.
To fix this, run the tf_upgrade_v2 script.
tf_upgrade_v2 --infile=YOUR_SCRIPT.py --outfile=YOUR_SCRIPT.py
Faced same issue on Ubuntu 16LTS when tensor flow was installed over existing python installation.
Workaround:
1.)Uninstall tensorflow from pip and pip3
sudo pip uninstall tensorflow
sudo pip3 uninstall tensorflow
2.)Uninstall python & python3
sudo apt-get remove python-dev python3-dev python-pip python3-pip
3.)Install only a single version of python(I used python 3)
sudo apt-get install python3-dev python3-pip
4.)Install tensorflow to python3
sudo pip3 install --upgrade pip
for non GPU tensorflow, run this command
sudo pip3 install --upgrade tensorflow
for GPU tensorflow, run below command
sudo pip3 install --upgrade tensorflow-gpu
Suggest not to install GPU and vanilla version of tensorflow
The error shows up because we are using tensorflow version 2 and the command is from version 1. So if we use:
tf.compat.v1.summary.(method_name)
It'll work
Because you cant use placeholder in tensflow2.0version, so you need to use tensflow1*, or you need to change your code to fix tensflow2.0
I had the same problem before after tried to upgrade tensorflow, I solved it by reinstalling Tensorflow and Keras.
pip uninstall tensorflow
pip uninstall keras
Then:
pip install tensorflow
pip install keras
The problem is with TensorFlow version; the one you are running is 2.0 or something above 1.5, while placeholder can only work with 1.4.
So simply uninstall TensorFlow, then install it again with version 1.4 and everything will work.
It may be the typo if you incorrectly wrote the placeholder word.
In my case I misspelled it as placehoder and got the error like this:
AttributeError: 'module' object has no attribute 'placehoder'