sonnet import fails on: 'from graphs import Sonnet' - python

Trying to run some github code which imports 'sonnet' which seems to import other packages from 'graphs'. I get:
----> 9 import sonnet as snt
~\Anaconda3\lib\site-packages\sonnet\__init__.py in <module>()
1 __version__ = '0.1.6'
----> 2 from graphs import Sonnet, D3Graph, MatplotGraph
ImportError: cannot import name 'Sonnet'
I've explicitly installed and imported 'graphs', but failed with the same error when explicitly tried to:
----> 1 from graphs import Sonnet
ImportError: cannot import name 'Sonnet'
Any advice?
Environment: Jupyter Notebook, python 3.6.5, Anaconda, windows

Try this.
pip uninstall sonnet;
pip install dm-sonnet

Related

CHEMBL : Can't import new_client from chembl_webresource_client.new_client

I have installed the chembl_webresource_client package.
Then I tried to import a module from the package:
from chembl_webresource_client.new_client import new_client
But it fails to execute and this error appears:
ImportError Traceback (most recent call
last) in ()
1 # Import necessary libraries
2 import pandas as pd
----> 3 from chembl_webresource_client.new_client import new_client
4 frames
/usr/local/lib/python3.7/dist-packages/chembl_webresource_client/cache.py
in ()
1 author = 'mnowotka'
2
----> 3 from requests_cache.backends.base import BaseCache, hashlib, _to_bytes
4
5 def create_key(self, request):
ImportError: cannot import name 'hashlib' from
'requests_cache.backends.base'
(/usr/local/lib/python3.7/dist-packages/requests_cache/backends/base.py)
Is there a fix for this?
I have faced the same issue today and resolved it by updating chembl-webresource-client library's version from 0.10.2 to 0.10.3 in my project's requirements.txt file.
For example: chembl-webresource-client==0.10.3
Also after making these changes and activating your project's virtual environment, please don't forget to fetch and re-install all listed libraries in your requirements.txt using the following command:
pip install -r .\requirements.txt

ModuleNotFoundError: No module named 'keras.backend.tensorflow_backend'

I am trying to run the code
import keras
And I am getting this stack trace.
I have tried reinstalling keras and tensorflow but nothing in working.
Here is the stack trace.
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-10-88d96843a926> in <module>
----> 1 import keras
~\Anaconda3\lib\site-packages\keras\__init__.py in <module>
1 from __future__ import absolute_import
2
----> 3 from . import utils
4 from . import activations
5 from . import applications
~\Anaconda3\lib\site-packages\keras\utils\__init__.py in <module>
4 from . import data_utils
5 from . import io_utils
----> 6 from . import conv_utils
7 from . import losses_utils
8 from . import metrics_utils
~\Anaconda3\lib\site-packages\keras\utils\conv_utils.py in <module>
7 from six.moves import range
8 import numpy as np
----> 9 from .. import backend as K
10
11
~\Anaconda3\lib\site-packages\keras\backend\__init__.py in <module>
----> 1 from .load_backend import epsilon
2 from .load_backend import set_epsilon
3 from .load_backend import floatx
4 from .load_backend import set_floatx
5 from .load_backend import cast_to_floatx
~\Anaconda3\lib\site-packages\keras\backend\load_backend.py in <module>
88 elif _BACKEND == 'tensorflow':
89 sys.stderr.write('Using TensorFlow backend.\n')
---> 90 from .tensorflow_backend import *
91 else:
92 # Try and load external backend.
ModuleNotFoundError: No module named 'keras.backend.tensorflow_backend'
Try:
pip install tensorflow==2.2.0
and then
pip install Keras==2.2.0
This worked for me with Python 3.7.
instead of use something like
from keras.backend.tensorflow_backend import set_session
Try to use it like
from keras.backend import set_session
In Tensorflow 2.0.0+ versions you should just put "compat.v1" after tf and dont use "tensorflow_backend" name. Like this:
tf.keras.backend.tensorflow_backend.set_session() -> tf.compat.v1.keras.backend.set_session()
I tried to use anaconda or pip to install tensorflow and keras, and each method met the same problem.
At last I found the problem is because the version of tensorflow or keras. When I install tensorflow==2.2 and keras==2.4.3(latest), no matter which tools I used I will meet this problem.When I install tensorflow==1.14 and keras==2.2, the code works well.
My python version is 3.5.2 under ubuntu 16.04
Just install tensorflow 2.1.0 or 2.2.0 It already has Keras inside. Dont mix using pip and conda. Carry on with what you have started.
pip install tensorflow==2.2.0
or,
conda install tensorflow==2.2.0
Uninstall Keras and reinstall the version 2.2.0 in your system, it will definately work with Tensorflow 2.2. Then you won't have to downgrade you tensorflow ie. less pain of changing codes ;)
pip uninstall keras
pip install Keras==2.2.0
For my case, I had Python 3.7(latest bug fix)
for tensorflow==2.4.1 this works:
from tensorflow.python.keras.backend import set_session
In my case, it was solved by installing a given specific version of Keras.
pip install Keras==2.2.4

is fastai.structured still a part of fast ai library

Why i am getting the error fastai.structured is not a module?.
i have tried installing previous versions of fastai. but nothing helped.
from fastai.imports import *
from fastai.structured import *
#from pandas_summary import DataFrameSummary
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from IPython.display import display
from sklearn import metrics
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-17-35432a48f631> in <module>()
1 from fastai.imports import *
----> 2 from fastai.structured import *
3
4 #from pandas_summary import DataFrameSummary
5 from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
ModuleNotFoundError: No module named 'fastai.structured'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
That module is no longer included in fastai's default python packages. Your default setup commands for using fastai packages will no longer includes that module. You may need to download it from the GitHub master, save it to your working directory, and import from your working directory to your jupyter notebook.
Here's a note from the fastai forum:
The structured.py has been moved to folder “old” (in anticipation to fastai_v1).
https://github.com/fastai/fastai/blob/master/old/fastai/structured.py
--- Andrei Oct '18
When importing from your working directory:
from structured import *
This will replace:
from fastai.structured import *
The module’s name has been changed to “tabular”. So use “from fastai.tabular import *” instead.
see this >> https://forums.fast.ai/t/modulenotfounderror-no-module-named-fastai-structured/36904

Numpy & Matplotlib suddenly cannot be imported in Atom although it works fine in the Terminal

I'm regularly importing Matplotlib Numpy PySide2 in Atom. They unexpectedly cannot be import for an unknown reason and then appear to be again re-importable, again unexplained.
When trying to import matplotlib with the following command
import matplotlib.pyplot as plt
This scripts runs without problems when I run in a Jupyter notebook or through the Terminal. But When trying to run on Hydrogen in Atom, I get the following error message:
File "<ipython-input-3-3dc8365ef973>", line 6
ModuleNotFoundError: No module named 'matplotlib.backends'; 'matplotlib' is not a package
^
SyntaxError: invalid syntax
I get the same error with Pyside2 when trying to run the line
from PySide2.QtWidgets import QApplication, QLabel
I get the error message
ModuleNotFoundError: No module named 'PySide2.QtWidgets'; 'PySide2' is not a package
Here is the path of python (after having typed which python in the Terminal): /anaconda3/bin/python
I checked that the matplotlib is installed by running the command conda list in the Terminal and got (among all the other packages) those lines:
matplotlib 2.1.2 py36h6d6146d_0
matplotlib 2.2.2 <pip>
PySide2 5.9.0a1.dev1525348214
I tried to run the following command in the Terminal but didn't solve the problem
sudo apt-get install python3-matplotlib
sudo pip3 install matplotlib
I had a similar issue with numpy when trying to import import numpy. Although import numpy was not a problem an hour ago, I get now the following error message (it seems it wants to connect to a previously used script in which numpy was used, to open numpy itself):
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-592c151f282b> in <module>()
1 # from numpy import genfromtxt as gft
----> 2 import numpy
~/Downloads/numpy.py in <module>()
----> 1 from numpy import genfromtxt
2 my_data = genfromtxt('/Users/mymac/Documents/PyQt/image_viewer/csv_file_generator/eggs.csv',
3 delimiter=',',
4 dtype=None,
5 encoding=None)
ImportError: cannot import name 'genfromtxt'
I had the same issue when tryin to import opencv2: I got the following error message:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
ImportError: numpy.core.multiarray failed to import---------------------------
------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-8f6675581547> in <module>()
5 from PySide2.QtCore import *
6 from PySide2.QtGui import *
----> 7 import cv2
8 import numpy
9 import csv
ImportError: numpy.core.multiarray failed to import
I visited the following site which didn't help me (or I didn't understand how to implement exactly the steps to fix the problem)
ImportError: No module named matplotlib.pyplot
Importing matplotlib.pyplot in atom editor
matplotlib Error: No module named matplotlib even though it is installed
I'm running on/with
python 3.6.5
macOS 10.13.4
Atom 1.27.0 x64
Hydrogen 2.4.1

Pip not installing package properly

So I am trying to get hmmlearn working in Jupyter, and I have come across an error while installing Hmmlearn using pip. I have tried this solution, but it didn't work.
It seems to me that pip does install the _hmmc file, but it does so incorrect. instead it has the name
_hmmc.cp35-win_amd64
and the file extesion is .PYD, instead of .c
When I run the code to import it, I get this error :
ImportError Traceback (most recent call last)
<ipython-input-1-dee84c3d5ff9> in <module>()
7 import os
8 from pyAudioAnalysis import audioBasicIO as aB
----> 9 from pyAudioAnalysis import audioAnalysis as aA
C:\Users\gover_000\Documents\GitHub\Emotion-Recognition-Prototype\pyAudioAnalysis\audioAnalysis.py in <module>()
15 import audioFeatureExtraction as aF
16 import audioTrainTest as aT
---> 17 import audioSegmentation as aS
18 import audioVisualization as aV
19 import audioBasicIO
C:\Users\gover_000\Documents\GitHub\Emotion-Recognition-Prototype\pyAudioAnalysis\audioSegmentation.py in <module>()
16 import sklearn
17 import sklearn.cluster
---> 18 import hmmlearn.hmm
19 import cPickle
20 import glob
C:\Users\gover_000\Anaconda3\envs\python2\lib\site-packages\hmmlearn\hmm.py in <module>()
19 from sklearn.utils import check_random_state
20
---> 21 from .base import _BaseHMM
22 from .utils import iter_from_X_lengths, normalize
23
C:\Users\gover_000\Anaconda3\envs\python2\lib\site-packages\hmmlearn\base.py in <module>()
11 from sklearn.utils.validation import check_is_fitted
12
---> 13 from . import _hmmc
14 from .utils import normalize, log_normalize, iter_from_X_lengths
15
ImportError: cannot import name _hmmc
I don't know why pip just doesn't install it correctly, even when I tried to use --no-cache-dir
Edit: So i figured out what the problem was. my active python enviroment was python 3.5, as i was manually transferring the installed files to my enviroment, it failed because i had the wrong version.
I had to change my active python enviroment: using activate <my_enviroment name>
after that i could just use pip to install it again and it worked this time.
Looking at your error message I guess that you have downloaded the hmmlearn package from GIT. Have you tried using a wheel (*.whl) file instead? You can download one from here. Check out which version fits your python installation.
Then use:
pip install <the_wheel_that_corresponds_to_your_python_version>.whl
Hope it helps.
So i figured out what the problem was. my active python enviroment was python 3.5, as i was manually transferring the installed files to my enviroment, it failed because i had the wrong version. I had to change my active python enviroment: using activate <my_enviroment_name> after that i could just use pip to install it again and it worked this time.
not sure if it could be helpful to anyone but I installed hmmlearn as follows in my Jupyter Lab:
import sys
!{sys.executable} -m pip install hmmlearn

Categories

Resources