numpypycharmpython-3.8

cannot import name 'int' from 'numpy'


I was just getting started with PyCharm and python for statistics. And I got this error:

ImportError: cannot import name 'int' from 'numpy' (/home/tetiana/.local/lib/python3.8/site-packages/numpy/__init__.py)

Full traceback looks like this:\
Traceback (most recent call last):\
File "/home/tetiana/forVScode/python/first/first_try.py", line 1, in <module>
    from scipy import stats\
File "/usr/lib/python3/dist-packages/scipy/stats/__init__.py", line 379, in <module>
    from .stats import *\
  File "/usr/lib/python3/dist-packages/scipy/stats/stats.py", line 180, in <module>
    import scipy.special as special\
  File "/usr/lib/python3/dist-packages/scipy/special/__init__.py", line 643, in <module>
    from .basic import *\
  File "/usr/lib/python3/dist-packages/scipy/special/basic.py", line 19, in <module>
    from . import orthogonal\
  File "/usr/lib/python3/dist-packages/scipy/special/orthogonal.py", line 81, in <module>
    from numpy import (exp, inf, pi, sqrt, floor, sin, cos, around, int,\
ImportError: cannot import name 'int' from 'numpy' (/home/tetiana/.local/lib/python3.8/site-packages/numpy/__init__.py)

Process finished with exit code 1

How can I fix it? Here is my code:

from scipy import stats
import pandas as pd

state = pd.read_csv('state_murder_rate_test_table.csv')
state['Population'].mean()
stats.trim_mean(state['Population'], 0.1)
state['Population'].median()

I checked whether the Python versions in os and in the project match and they are. I have python 3.8.10 and my os is Ubuntu 20.04


Solution

  • Referring to the current numpy documentation, there exists no type called numpy.int that you can import. I believe that the type you wanna import is numpy.integer or numpy.int_.

    The code you provided does not have any statement like: from numpy import int. If you could provide a full traceback error, it'll be easier to see where the error stems from.

    I hope this answer will be somewhat useful.