Issue importing pandas library 'module' object has no attribute 'python_version' - python

My anaconda-based pandas install was working fine and then I got this error:
Traceback (most recent call last):
File "/xx/xx/test.py", line 3, in <module>
import pandas
File "/home/sc9/anaconda/lib/python2.7/site-packages/pandas/__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
File "tslib.pyx", line 39, in init pandas.tslib (pandas/tslib.c:63127)
File "/home/sc9/anaconda/lib/python2.7/site-packages/pytz/__init__.py", line 29, in <module>
from pkg_resources import resource_stream
File "/home/sc9/anaconda/lib/python2.7/site-packages/setuptools-12.3-py2.7.egg/pkg_resources/__init__.py", line 1366, in <module>
File "/home/sc9/anaconda/lib/python2.7/site-packages/setuptools-12.3-py2.7.egg/pkg_resources/__init__.py", line 1370, in MarkerEvaluation
AttributeError: 'module' object has no attribute 'python_version'
running python test.py on this simple file is enough to reproduce:
#!/usr/bin/env python
import pandas
I think this line (1370) 'python_full_version': platform.python_version might be the problem as platform.py does not have a python_version attribute only the python_version() function. However I have never changed this and I don't see why it has stopped working when all was fine.
This error has also followed me from one ubuntu machine to another so I guess it must be something I'm doing in code rather than a corrupted library.
Strangely an IPython (2.2.0) console can run import pandas as pd fine but a regular python console will fail with the same error as above. I can debug my code from Pycharm but can't run, which is bemusing to me.
Any help appreciated.
I am developing principally in Pycharm using using python 2.7.9 (Anaconda 2.1.0), Pandas 0.14.1 on Ubuntu 14.0.4
Update: I tried running the simple import from a different directory using a regular python console and it worked. I found an import statement which looks like it might be causing the problem with the project I was working on: from twisted.python.runtime import platform this is used to do a platform check. I thought removing this would fix the problem but it seems to be persisting somewhere because it does not fix the problem.

Related

Install module cbpro throws multiple errors in several other projects (python 3.10, pycharm)

I have made a few projects which run fine. A new project required me to install pip install cbpro (a module for dealing with coinbase cryptocurrency API).
After installing it, even running the simplest code throws several errors:
Input:
import cbpro
import pandas as pd
c = cbpro.PublicClient()
data = pd.DataFrame(c.get_products())
data.tail().T
Errors:
Traceback (most recent call last):
File "/Users/me/PycharmProjects/stonks/coinbase_interface.py", line 1, in <module>
import cbpro
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cbpro/__init__.py", line 1, in <module>
from cbpro.authenticated_client import AuthenticatedClient
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cbpro/authenticated_client.py", line 10, in <module>
import requests
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/__init__.py", line 63, in <module>
from . import utils
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/utils.py", line 29, in <module>
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/cookies.py", line 174, in <module>
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
Secondly, when I then go to other projects that were working well, I get additional errors. Of note, those projects start with:
import pandas as pd
import requests
import json
Errors:
Traceback (most recent call last):
File "/Users/me/PycharmProjects/stonks/historical_crypto_pull.py", line 2, in <module>
import requests
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/__init__.py", line 63, in <module>
from . import utils
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/utils.py", line 29, in <module>
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/cookies.py", line 174, in <module>
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
Things I've tried:
If I uninstall cbpro, then uninstall and reinstall requests, I can undo the error and am back where I started. However, I'm interested in knowing why I am encountering these errors because I'd like to actually use cbpro and know how to solve this issue in the future.
The libraries I was using were not compatible with Python 3.10. I am still at a loss for how I would inherently know that based on the errors thrown, but since then my solution was to install Python 3.9 and see if I still get the same errors when running 3.9.
(Then I also read that it might be a better idea for my current purposes to use a slightly older version of Python, so I moved over to 3.9 completely and haven't had the same issue again.)

Music21 AttributeError: module 'importlib' has no attribute 'util'

I'm trying to get started using music21 in python. I've imported the package into PyCharm but when I use the line:
import music21
at the start of my file, it gives me:
Traceback (most recent call last):
File "C:/Users/Miles/Documents/Miles/Uni/Coding/Music21/Start.py", line 1, in <module>
import music21
File "C:\Users\Miles\Documents\Miles\Uni\Coding\Music21\venv\Environment\lib\site-packages\music21\__init__.py", line 169, in <module>
from music21 import base # noqa: E402
File "C:\Users\Miles\Documents\Miles\Uni\Coding\Music21\venv\Environment\lib\site-packages\music21\base.py", line 119, in <module>
loader = importlib.util.find_spec(modName)
AttributeError: module 'importlib' has no attribute 'util'
It works fine when I try to run it from the python console, and I'm using python 3.7 and music21 version 6.5 which should be compatible so not sure where I'm going wrong.
Fixed in the unreleased version (current development branch on GitHub).
See this issue and linked PR:
https://github.com/cuthbertLab/music21/issues/750
Since you are saying it works for you in python console, I suggest installing music21 package in PyCharm. Refer the following document for installing packages in PyCharm.
https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html

Error Import awswrangler: AttributeError: module 'multiprocessing' has no attribute 'connection'

I have a python script that uses the lib awswrangler. Today my scrpit started to give errors in the import of the library and I don't know what is happening.
I'm running the script in a docker container with image python: 3.8
Example:
import awswrangler as wr
print(wr.__version__)
Error:
Traceback (most recent call last):
File "src/avec/automation/TaskBaseUserPass.py", line 1, in <module>
from awswrangler.pandas import Pandas
File "/usr/local/lib/python3.8/site-packages/awswrangler/__init__.py", line 17, in <module>
from awswrangler.pandas import Pandas # noqa
File "/usr/local/lib/python3.8/site-packages/awswrangler/pandas.py", line 45, in <module>
class Pandas:
File "/usr/local/lib/python3.8/site-packages/awswrangler/pandas.py", line 273, in Pandas
def _read_csv_once_remote(send_pipe: mp.connection.Connection, session_primitives: "SessionPrimitives",
AttributeError: module 'multiprocessing' has no attribute 'connection'
I have been experienced the same issue today when trying to import awswrangler. For me, downgrading the following dependencies helped:
pip install fsspec==0.6.3 PyAthena==1.10.2 s3fs==0.4.0
It seems that one or more of them were causing the problem.
If your code uses multiprocessing.connection.Listener or multiprocessing.connection.Client, then you should use:
import multiprocessing.connection
If you just use
import multiprocessing
.. then your code might get an ImportError or not. It depends on other modules. If an other module imports multiprocessing.connection, then it will work.
But I guess you don't want random behavior, and that's why you should import multiprocessing.connection.
I managed to run version 3.6, the library has a problem with mp.connection.Connection in current python versions

Python igraph import error on Windows

I've installed igraph form .whl file using pip install. When I was trying to test the correctness of installation
import igraph.test
igraph.test.test()
I got this error:
Traceback (most recent call last):
File "D:/Nauka/Praca-inzynierska/Barabasi-Albert.py", line 4, in <module>
import igraph.test
File "D:\Programy\Python 3.5\lib\site-packages\igraph\__init__.py", line 34, in <module>
from igraph._igraph import *
ImportError: No module named 'igraph._igraph'
(the same error pops out if I'm trying to import igraph not igraph.test).
I've tried adding path (I don't know if this is rigth):
import sys
sys.path.append ("D:/Programy/Python 3.5/Lib/site-packages/igraph")
but it didn't work.
One thing I discovered is that if I delete "__init__" file from igraph folder I can import igraph without error, but it doesn't work for igraph.test.
If it's relevant I have Python 2.7 installed on my machine alongside Python 3.5.
Thank you in advance for any help.

Python/Flask error: “ImportError: cannot import name _compare_digest”

I run linux mint 17.2 XCFE on my computer.
My issue is nearly identical to the one found in this thread, except I tried all of the solutions offered and none worked. It's worth noting that as a result of me trying to fiddle with python, my machine now runs 2.7.8 and the venv runs 2.7.6, which is easy to fix but might be relevant.
I also consulted this and this, and tried changing the name of file called operator and a different virtualenv command as suggested in those, but nothing worked. (Note: I then changed the name of that file back to operator just because since that wasn't the problem I'd rather not mess with it).
When I try to run a very simple script for flask newbs I keep encountering the same error.
(venv)joshua#joshua-ThinkPad-Edge-E430 ~/website/projects/helloapp $ python hello.py
Traceback (most recent call last):
File "hello.py", line 1, in <module>
from flask import Flask
File "/home/joshua/website/projects/helloapp/venv/lib/python2.7/site-packages/flask/__init__.py", line 21, in <module>
from .app import Flask, Request, Response
File "/home/joshua/website/projects/helloapp/venv/lib/python2.7/site-packages/flask/app.py", line 26, in <module>
from . import json
File "/home/joshua/website/projects/helloapp/venv/lib/python2.7/site-packages/flask/json.py", line 25, in <module>
from itsdangerous import json as _json
File "/home/joshua/website/projects/helloapp/venv/lib/python2.7/site-packages/itsdangerous.py", line 14, in <module>
import hmac
File "/home/joshua/anaconda/lib/python2.7/hmac.py", line 8, in <module>
from operator import _compare_digest as compare_digest
ImportError: cannot import name _compare_digest
I have been trying to figure out a solution on my own for hours but I've had no luck. I think it might have to do with Anaconda but I'm not sure what could be done if that's the case.
As it turns out the issue was that the hmac.py file had a reference to a method that it appears no longer existed. I disabled that reference with '#' (just incase it turns out it was important) and it started working.

Categories

Resources