AttributeError: module 'numpy.random' has no attribute 'mtrand' - python

After having installed the pyclustertend package with pip install pyclustertend, I now try to import it into Python:
from pyclustertent import ivat
However, I get the following error while doing so:
Traceback (most recent call last):
File "", line 1, in
from pyclustertend import ivat
File "C:\Users\Emil\AppData\Roaming\Python\Python38\site-packages\pyclustertend_init_.py", line 1, in
from .hopkins import hopkins # noqa: F401
File "C:\Users\Emil\AppData\Roaming\Python\Python38\site-packages\pyclustertend\hopkins.py", line 5, in <module>
from sklearn.neighbors import BallTree
File "C:\Users\Emil\Anaconda3\lib\site-packages\sklearn\__init__.py", line 82, in <module>
from .base import clone
File "C:\Users\Emil\Anaconda3\lib\site-packages\sklearn\base.py", line 17, in <module>
from .utils import _IS_32BIT
File "C:\Users\Emil\Anaconda3\lib\site-packages\sklearn\utils\__init__.py", line 29, in <module>
from .fixes import parse_version, threadpool_info
File "C:\Users\Emil\Anaconda3\lib\site-packages\sklearn\utils\fixes.py", line 47, in <module>
class loguniform(scipy.stats.reciprocal):
File "C:\Users\Emil\Anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 1601, in __init__
super(rv_continuous, self).__init__(seed)
File "C:\Users\Emil\Anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 588, in __init__
self._random_state = check_random_state(seed)
File "C:\Users\Emil\Anaconda3\lib\site-packages\scipy\_lib\_util.py", line 202, in check_random_state
return np.random.mtrand._rand
AttributeError: module 'numpy.random' has no attribute 'mtrand'
I suspected this has to do with the Numpy version. However, during the installation, it updated numpy to an older version:
Successfully uninstalled numpy-1.23.4
Successfully installed numpy-1.20.3 pyclustertend-1.8.2
What do I need to do to use this package?

Related

Importing Pytest fails with "AttributeError: 'str' object has no attribute 'pattern'"

Trying to import pytest on Python 3.8 fails with the following error:
>>> import pytest
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\pytest\__init__.py", line 6, in <module>
from _pytest.assertion import register_assert_rewrite
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\_pytest\assertion\__init__.py", line 7, in <module>
from _pytest.assertion import rewrite
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\_pytest\assertion\rewrite.py", line 24, in <module>
from _pytest.assertion import util
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\_pytest\assertion\util.py", line 14, in <module>
import _pytest._code
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\_pytest\_code\__init__.py", line 2, in <module>
from .code import Code # noqa
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\_pytest\_code\code.py", line 28, in <module>
import pluggy
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\pluggy\__init__.py", line 16, in <module>
from .manager import PluginManager, PluginValidationError
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\pluggy\manager.py", line 6, in <module>
import importlib_metadata
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\importlib_metadata\__init__.py", line 478, in <module>
__version__ = version(__name__)
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\importlib_metadata\__init__.py", line 445, in version
return distribution(package).version
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\importlib_metadata\__init__.py", line 418, in distribution
return Distribution.from_name(package)
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\site-packages\importlib_metadata\__init__.py", line 179, in from_name
dists = resolver(name)
File "<frozen importlib._bootstrap_external>", line 1382, in find_distributions
File "C:\Users\Al\AppData\Local\Programs\Python\Python38\lib\importlib\metadata.py", line 379, in find_distributions
found = cls._search_paths(context.pattern, context.path)
AttributeError: 'str' object has no attribute 'pattern'
How do I fix this?
This was fixed on November 11, 2019 in this commit.
The solution is to update the pluggy dependency (the error happens in version 0.12.0) by running pip install -U pluggy (or pip3 install -U pluggy on macOS and Linux). Simply updating pytest is not enough to update its dependency.
After running pip, you should be able to import pytest without error.

python sklearn import failed on libquadmath.so.0 in 3.5.1

Getting import Error while importing sklearn , the only Error code what it says is libquadmath.so.0 which i'm unale to see on the pkg path but same module works fine in 3.6.1.
>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/python3/lib/python3.5/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "/python3/lib/python3.5/site-packages/sklearn/base.py", line 11, in <module>
from .utils.fixes import signature
File "/python3/lib/python3.5/site-packages/sklearn/utils/__init__.py", line 11, in <module>
from .validation import (as_float_array,
File "/python3/lib/python3.5/site-packages/sklearn/utils/validation.py", line 16, in <module>
from ..utils.fixes import signature
File "/python3/lib/python3.5/site-packages/sklearn/utils/fixes.py", line 324, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "/python3/lib/python3.5/site-packages/scipy-0.18.0rc2-py3.5-linux-x86_64.egg/scipy/sparse/linalg/__init__.py", line 112, in <module>
from .isolve import *
File "/python3/lib/python3.5/site-packages/scipy-0.18.0rc2-py3.5-linux-x86_64.egg/scipy/sparse/linalg/isolve/__init__.py", line 6, in <module>
from .iterative import *
File "/python3/lib/python3.5/site-packages/scipy-0.18.0rc2-py3.5-linux-x86_64.egg/scipy/sparse/linalg/isolve/iterative.py", line 7, in <module>
from . import _iterative
ImportError: libquadmath.so.0: cannot open shared object file: No such file or directory

AttributeError: 'module' object has no attribute 'tokenize'

I have nltk installed in my virtualenv. When I do pip freeze , among other packages I can see nltk==3.2.1.
I am using Ubuntu 14.04 and python 2.7. And After activating virtualenv, when I try to import nltk from python shell, I get following error.
>>> import nltk
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/nltk/__init__.py", line 128, in <module>
from nltk.chunk import * File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/nltk/chunk/__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/nltk/chunk/api.py", line 13, in <module>
from nltk.parse import ParserI File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/nltk/parse/__init__.py", line 79, in <module>
from nltk.parse.transitionparser import TransitionParser File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/nltk/parse/transitionparser.py", line 21, in <module>
from sklearn.datasets import load_svmlight_file File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/base.py", line 11, in <module>
from .utils.fixes import signature File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/utils/__init__.py", line 17, in <module>
from ..externals.joblib import cpu_count File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/externals/joblib/__init__.py", line 127, in <module>
from .parallel import Parallel File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 30, in <module>
from .format_stack import format_exc, format_outer_frames File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/externals/joblib/format_stack.py", line 35, in <module>
generate_tokens = tokenize.tokenize AttributeError: 'module' object has no attribute 'tokenize'
How can I solve this problem?

Install Error Pygame

I have Ubuntu 12.04 with Python 2.7 and Python 3 installed. I installed pygame through sudo apt-get python-pygame and also from the source. When I tried >>>import pygame on Python I get this error:
`
>>> import pygame<br>
Jello, world!<br>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pygame/__init__.py", line 255, in <module>
try: import pygame.surfarray
File "/usr/lib/python2.7/dist-packages/pygame/surfarray.py", line 69, in <module>
import pygame._numpysurfarray as numpysf
File "/usr/lib/python2.7/dist-packages/pygame/_numpysurfarray.py", line 48, in <module>
import numpy
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
import polynomial
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/__init__.py", line 18, in <module>
from polynomial import Polynomial
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/polynomial.py", line 60, in <module>
from polytemplate import polytemplate
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/polytemplate.py", line 20, in <module>
polytemplate = string.Template('''
AttributeError: 'module' object has no attribute 'Template'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 66, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 1, in <module>
from apport.report import Report
File "/usr/lib/python2.7/dist-packages/apport/report.py", line 18, in <module>
import problem_report
File "/usr/lib/python2.7/dist-packages/problem_report.py", line 16, in <module>
from email.mime.multipart import MIMEMultipart
File "/usr/lib/python2.7/email/mime/multipart.py", line 9, in <module>
from email.mime.base import MIMEBase
File "/usr/lib/python2.7/email/mime/base.py", line 9, in <module>
from email import message
File "/usr/lib/python2.7/email/message.py", line 16, in <module>
import email.charset
File "/usr/lib/python2.7/email/charset.py", line 14, in <module>
import email.quoprimime
File "/usr/lib/python2.7/email/quoprimime.py", line 48, in <module>
from string import hexdigits
ImportError: cannot import name hexdigits
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/pygame/__init__.py", line 255, in <module>
try: import pygame.surfarray
File "/usr/lib/python2.7/dist-packages/pygame/surfarray.py", line 69, in <module>
import pygame._numpysurfarray as numpysf
File "/usr/lib/python2.7/dist-packages/pygame/_numpysurfarray.py", line 48, in <module>
import numpy
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 153, in <module>
import polynomial
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/__init__.py", line 18, in <module>
from polynomial import Polynomial
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/polynomial.py", line 60, in <module>
from polytemplate import polytemplate
File "/usr/lib/python2.7/dist-packages/numpy/polynomial/polytemplate.py", line 20, in <module>
polytemplate = string.Template('''
AttributeError: 'module' object has no attribute 'Template'
I saw the Jello World so I guess it is working a bit. I dont know what to do. I appreciate the help. Thanks in advance.
That looks like you don't have SDL installed on your box.
Remove your current pygame packages then dot he following:
wget http://www.libsdl.org/release/SDL-1.2.14.tar.gz
tar -xzvf SDL-1.2.14.tar.gz
cd SDL-1.2.14
./configure
make
make install
Once this has completed reinstall pygame but try reinstalling via easy_install or pip:
easy_install pygame
or
pip install pygame
You should be good to go after that.

attribute error on numpy import with python 2.7 and wxpython

I am struggling to get an ide working for python 2.7 with numpy, scipy, matplotlib and wxpython/PyQt installed. Running the ide spyder throws up the message "module 'object' has no attribute 'core'" for numpy. Same message occurs while "from numpy import *" on IDLE.
Here is the whole message. Please help. Thanks!
C:\Python27\Scripts>C:\Python27\python.exe "C:\Python27\Scripts\spyder"
Traceback (most recent call last):
File "C:\Python27\Scripts\spyder", line 2, in <module>
from spyderlib import spyder
File "C:\Python27\lib\site-packages\spyderlib\spyder.py", line 96, in <module>
from spyderlib.utils.environ import WinUserEnvDialog
File "C:\Python27\lib\site-packages\spyderlib\utils\environ.py", line 17, in <module>
from spyderlib.widgets.dicteditor import DictEditor
File "C:\Python27\lib\site-packages\spyderlib\widgets\dicteditor.py", line 31, in <module>
from spyderlib.config import get_icon, get_font
File "C:\Python27\lib\site-packages\spyderlib\config.py", line 27, in <module>
from spyderlib.utils import iofuncs, codeanalysis
File "C:\Python27\lib\site-packages\spyderlib\utils\iofuncs.py", line 61, in <module>
import numpy as np
File "C:\Users\User\AppData\Roaming\Python\Python27\site-packages\numpy\__init__.py", line 137, in <module>
import add_newdocs
File "C:\Users\User\AppData\Roaming\Python\Python27\site-packages\numpy\add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "C:\Users\User\AppData\Roaming\Python\Python27\site-packages\numpy\lib\__init__.py", line 13, in <module>
from polynomial import *
File "C:\Users\User\AppData\Roaming\Python\Python27\site-packages\numpy\lib\polynomial.py", line 11, in <module>
import numpy.core.numeric as NX
AttributeError: 'module' object has no attribute 'core'

Categories

Resources