Home > Back-end >  Python3 error when running a pandas simple program
Python3 error when running a pandas simple program

Time:06-22

I'm trying to run a python program that uses the pandas library on Mac OS, and I get the next error

adan_vazquez@EPAM-C02G513RML7L automate_python % python3 test_pandas.py 
Traceback (most recent call last):
  File "/Users/adan_vazquez/Desktop/automate_python/test_pandas.py", line 1, in <module>
    import pandas as pd
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/__init__.py", line 11, in <module>
    __import__(dependency)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/__init__.py", line 155, in <module>
    from . import random
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/random/__init__.py", line 180, in <module>
    from . import _pickle
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/random/_pickle.py", line 1, in <module>
    from .mtrand import RandomState
  File "mtrand.pyx", line 1, in init numpy.random.mtrand
  File "bit_generator.pyx", line 40, in init numpy.random.bit_generator
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/secrets.py", line 19, in <module>
    from random import SystemRandom
  File "/Users/adan_vazquez/Desktop/automate_python/random.py", line 3, in <module>
    print(random.randint(1,10))
AttributeError: partially initialized module 'random' has no attribute 'randint' (most likely due to a circular import)

Here's the code that I'm trying to run:

import pandas as pd

simpsons = pd.read_html('https://en.wikipedia.org/wiki/List_of_The_Simpsons_episodes_(seasons_1–20)')

print(len(simpsons))

print("Hola")

As you can see is not a big code and I'm getting the error, I already updated my pip3 and my python3 versions, also I reinstall pandas and I keep getting the error, if I try to import pandas in the python terminal I get the same error and I don't know what's causing it, I hope you can help me, thanks in advance.

CodePudding user response:

The error message says it is a circular import error. Try renaming /Users/adan_vazquez/Desktop/automate_python/random.py with something other than random

CodePudding user response:

According to the error, it is a circular import which is causing the problem.

Since I do not have the details of your project structure or file name, my best guess is that you accidentally named your working file the same as the module name and those modules depend on each other.

  • Related