ImportError: cannot import name Serializer - python

I am using python 2.7 and trying to run python-xbrl package. Following exact instructions here, but every time I try import xbrl or from xbrl import XBRLParser, GAAP, GAAPSerializer I get
ImportError Traceback (most recent call last)
<ipython-input-2-ccb496289539> in <module>()
----> 1 import xbrl
/usr/local/lib/python2.7/dist-packages/xbrl/__init__.py in <module>()
6 version = (1, 1, 0)
7
----> 8 from .xbrl import XBRLParser, GAAP, GAAPSerializer, XBRLParserException
/usr/local/lib/python2.7/dist-packages/xbrl/xbrl.py in <module>()
3
4 import re
----> 5 from marshmallow import Serializer, fields
6 import datetime
7 import collections
ImportError: cannot import name Serializer
So far I have updated all the required packages (pytest, pep8, marshmallow, beautifulsoup4, ordereddict, lxml, six) and updated python-xbrl, but I still get the same error.

It is a matter of the marshmallow version. Try -
pip uninstall marshmallow
pip install marshmallow==1.2.6

I believe this is a known issue, as seen here.
We just have to install the latest update from github.
sudo pip install git+https://github.com/greedo/python-xbrl.git

Related

stackstac on Google Colab results in ImportError: cannot import name 'Protocol' from 'typing'

I'm unable to install stackstac on Google Colab. This is reproducible with the code below.
!pip install stackstac
import stackstac
outputs:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-c01f370957f7> in <module>()
1 get_ipython().system('pip install stackstac')
----> 2 import stackstac
1 frames
/usr/local/lib/python3.7/dist-packages/stackstac/rio_reader.py in <module>()
5 import threading
6 import weakref
----> 7 from typing import TYPE_CHECKING, Optional, Protocol, Tuple, Type, Union
8
9 import numpy as np
ImportError: cannot import name 'Protocol' from 'typing' (/usr/lib/python3.7/typing.py)
---------------------------------------------------------------------------
Same issue on a local instance how ever that solution doesn't translate.
Protocol was introduced to typing as of Python 3.8, as can be seen in the docs. You appear to be running Python 3.7, based on your file paths - upgrade to use Python 3.8 or later if you can.

chembl_webresource_client install failed on google colab

need your help, I tried to install the chembl_webresource_client on colab, it usually works fine, but today to my surprise there is a mistake in the very first step.
! pip install chembl_webresource_client # install the client
from chembl_webresource_client.new_client import new_client # here is where is wrong
molecule = new_client.molecule
res = molecule.search('viagra')
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-7-19aed0e54aea> in <module>()
----> 1 from chembl_webresource_client.new_client import new_client
2 molecule = new_client.molecule
3 res = molecule.search('viagra')
4 frames
/usr/local/lib/python3.7/dist-packages/chembl_webresource_client/cache.py in <module>()
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)
---------------------------------------------------------------------------
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.
This is an issue with requests-cache. I downgraded to 0.5.2 and the error goes away.
This issue was fixed on version 0.10.3 of the chembl_webresource_client. Upgrading should fix it

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

PyHive[Hive] on REHL7 ImportError: libsasl2.so.2: cannot open shared object file: No such file or directory

I can't seem to get PyHive to work correctly. Yum reports
Package cyrus-sasl-lib-2.1.26-20.el7_2.x86_64 already installed and latest version.
Hope I am just missing something. Please help?
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-ce1195d3db11> in <module>()
----> 1 from pyhive import hive
2 from TCLIService.ttypes import TOperationState
3 cursor = hive.connect('localhost').cursor()
4 cursor.execute('SELECT * FROM my_awesome_data LIMIT 10', async=True)
5
/opt/anaconda2/lib/python2.7/site-packages/pyhive/hive.py in <module>()
18 import getpass
19 import logging
---> 20 import sasl
21 import sys
22 import thrift.protocol.TBinaryProtocol
/opt/anaconda2/lib/python2.7/site-packages/sasl-0.2.1-py2.7-linux-x86_64.egg/sasl/__init__.py in <module>()
/opt/anaconda2/lib/python2.7/site-packages/sasl-0.2.1-py2.7-linux-x86_64.egg/sasl/saslwrapper.py in <module>()
/opt/anaconda2/lib/python2.7/site-packages/sasl-0.2.1-py2.7-linux-x86_64.egg/sasl/saslwrapper.py in __bootstrap__()
ImportError: libsasl2.so.2: cannot open shared object file: No such file or directory
I seem to have found further information in another libsasl-related question, and the solution in Cloudera's Python-SASL GitHub.
The problem is that the sasl Python package is linked to an older version of the native library: libsasl2.so.2, which existed on RHEL/CentOS 6. On RHEL/CentOS 7, there's libsasl2.so.3, installed by cyrus-sasl-lib into /usr/lib64/.
The solution is to reinstall the sasl Python package:
pip uninstall sasl
pip install sasl

ImportError: cannot import name murmurhash3_32

I am trying to use the sklearn.qda package in python. I have installed it successfully but when Itry to import it I get the error message below. Can anybody tell me what should I do to fix this?
In [3]: from sklearn.qda import QDA
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-7d7abf937d66> in <module>()
----> 1 from sklearn.qda import QDA
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/qda.py in <module>()
12
13 from .base import BaseEstimator, ClassifierMixin
---> 14 from .utils.fixes import unique
15 from .utils import check_arrays, array2d
16
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/utils/__init__.py in <module>()
7 import warnings
8
----> 9 from .murmurhash import murmurhash3_32
10 from .validation import (as_float_array, check_arrays, safe_asarray,
11 assert_all_finite, array2d, atleast2d_or_csc,
ImportError: cannot import name murmurhash3_32
I had the same problem, I run:
sudo pip install -U scikit-learn
and now everything is working fine
I started a new shell and this problem went away
I faced the similar situation of getting mumurhash error while installing sklearn.preprocessing library.
I upgraded numpy version from 1.13 to 1.15
using
pip install --upgrade numpy
After this, I was able to import the sklearn library.
I fixed this by upgrading murmurhash to 1.0.5.
I faced a similar problem, so there are mainly two solutions
Either run it in administrator mode and install all the libraries and run in admin mode. Something that I would not recommend
Use virtualenv to install the libraries again and run your command in the virtualenv. This worked for me.
Hope this helps

Categories

Resources