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
Related
Basically, I recently started Python. I'm working on a project where I need audio to play. I searched up some libraries that can play audio and tried simpleaudio. I'm using Windows and sucessfull installed simpleaudio using: pip3 install simpleaudio.
However, when I tried to use simpleaudio in my project with import simpleaudio as sa, it gives me this error:
Traceback (most recent call last):
File "d:\coding\python\python projects\random tests\soundtest.py", line 1, in
import simpleaudio as sa
ModuleNotFoundError: No module named 'simpleaudio'
Any idea what is wrong?
After I installed simpleaudio, import simpleaudio as sa worked with no errors. I've run into similar errors before, and it was always because the version of pip I was using and the Python interpreter I was using didn't match. You probably need to either switch to using the same interpreter as pip3 or install the package for whatever interpreter you're using
The most probable issue is the use of differing version of python. For instance if you use pip3 it is for python3 only
Since the module was not found try
pip install simpleaudio
and then importing again
It's possible you installed the library for python2 instead of python3. In ubuntu pip is python2 and pip3 is python3- I'm not sure if that's the case on windows or not.
I am absolutely new to the development of deep learning and currently, I am just preparing my system to start with some basic tutorials.
I followed the Tutorial on this Blog to prepare the environment for the development of deep leaning projects.
I was successful to do the steps mentioned in the tutorial expect the last one. I Installed tensorflow-gpu using the command pip install tensorflow-gpu in the Python 3.7 Anaconda.
PROBLEM: As per the tutorial, I should try to execute the following commands to check if everything went OK with the installation:
>>> import tensorflow
>>> import keras
The first command was exectued without any issue but the second command (i.e. import keras) is throwing error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module names 'keras'
You installed tensorflow, thats why you can import keras from tensorflow
from tensorflow import keras
Or you install keras separately with:
pip install keras
and then import it with:
import keras
You can import keras by pip (command for use).
pip install keras
After completion of above command you can check whether Keras install or not in your system by
pip list | grep -i keras
Output on console
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
Keras (2.2.4)
Keras-Applications (1.0.7)
Keras-Preprocessing (1.0.9)
I have a working Python 3.6 and the package imutils is recognized, importable in its shell. Today I installed some packages on my Python 2 for another task, and now my IPython does not recognize imutils anymore:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-b01afa4ab41d> in <module>()
4 import random
5 import math
----> 6 import imutils
7 import re
8 import time
ImportError: No module named imutils
What's going on? How fragile are these things, seriously.
I run sys.executable on both environments and the result is the same:
/usr/bin/python3
I checked my Python2 and the package is not installed there:
sudo -H pip2.7 uninstall imutils
Skipping imutils as it is not installed.
Doing this:
/usr/bin/python3 -V
Returns this:
Python 3.6.7
Restarting does not work. I did use sudo commands, installed, uninstalled several times - no luck. Something has screwed up my Python, I think.
P.S: I do use Python3 on my IPython as interpreter.
P.S: I don't use Python 3.4 as a kernel whatsoever, they are all 3.6.
EDIT: Okay it is clear that ROS installation screwed up my Python path since I see this:
os.getenv("PYTHONPATH")
'/home/user/ros_ws/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages'
HOW CAN I SET IT BACK TO WHERE IT WAS BY DEFAULT?
It was due to the fact that ROS sourced its own Python version (2.7) by changing the PYTHONPATH.
Once I removed it from my .bashrc, it started to work again.
I have recently installed TensorFlow using the pip install instructions on the TensorFlow official website. Due to technical issues, I downgraded to Python version 3.6.2. However, when I entered IDLE, opened an additional file and entered:
import tensorflow as tf
Python responded with the message:
Traceback (most recent call last):
File "/Users/gg-mac/Documents/firsttensorflow.py", line 1, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
>>>
Is there any way to resolve this issue? I am simply trying to know where to run Tensorflow, as it is not specified anywhere on the website. I am developing an audio recognition program, if that is relevant. Thank you for any assistance you can provide.
Sincerely,
Suren Grigorian
This is hard to diagnose without more information, since we cannot test the absence of it. Perhaps try this:
pip3 install tensorflow
and try again, or perhaps run
python3 /Users/gg-mac/Documents/firsttensorflow.py
from the Terminal (looks like you're running Mac OS).
When trying to use yolo for python I followed https://github.com/thtrieu/darkflow I got flow installed using
pip3 install .
but then, when running
flow --h
I get
File "/home/computername/.local/lib/python3.5/site-packages/darkflow/net/help.py", line 9, in <module>
import cv2
ImportError: No module named 'cv2'
When I call python I get into python 3.6 and if the import cv2 it does not give any problem, i.e., cv2 is imported.
When calling
which python
I get
/home/computername/anaconda3/bin/python
So flow does call the wrong version python. I thought, maybe I should delete the python 3.5 version on my computer, but looking for how to do that I only find warnings that I should not do that.
So my question is: what to do such that it will work?
maybe other relevant information:
which pip3
/usr/bin/pip3
and (I tried to install flow with pip first, but that did not work)
which pip
/home/bombus/anaconda3/bin/pip
I am working on Ubuntu 16.04.3 LTS