4

I have been following a tutorial and after following the steps as listed by the instructor, I am stuck with the error below:

C:\Users\Angel\Documents\Python Basic> & C:/Users/Angel/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/Angel/Documents/Python Basic/pandaexample.py"
Traceback (most recent call last):
  File "c:/Users/Angel/Documents/Python Basic/pandaexample.py", line 3, in <module>
    import pandas
  File "C:\Users\Angel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\__init__.py", line 11, in <module>
    __import__(dependency)
  File "C:\Users\Angel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\numpy\__init__.py", line 152, in <module>
    from . import random
  File "C:\Users\Angel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\numpy\random\__init__.py", line 181, in <module>
    from . import _pickle
  File "C:\Users\Angel\AppData\Local\Programs\Python\Python38-32\lib\site-packages\numpy\random\_pickle.py", line 1, in <module>
    from .mtrand import RandomState
  File "_bit_generator.pxd", line 14, in init numpy.random.mtrand
  File "_bit_generator.pyx", line 40, in init numpy.random._bit_generator
  File "C:\Users\Angel\AppData\Local\Programs\Python\Python38-32\lib\secrets.py", line 20, in <module>
    from random import SystemRandom
  File "c:\Users\Angel\Documents\Python Basic\random.py", line 2, in <module>
    random.randint(1, 10)
AttributeError: partially initialized module 'random' has no attribute 'randint' (most likely due to a circular import)

here is the code


import time
import os
import pandas

while True:
    if os.path.exists("files/temps_today.csv"):
        data = pandas.read_csv("files/temps_today.csv")
        print(data.mean())
    else:
        print("file does not exist")
    time.sleep(10)

Please, your help is highly appreciated

PS: I successfully installed pandas

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Angel
  • 49
  • 4
  • 4
    Do I understand correct that you're running `pip install` from Python interpreter? Why? – bereal Jan 16 '20 at 10:17
  • that was the method the instructed used sir. I just followed but it seems i have messed up – Angel Jan 16 '20 at 10:21
  • 2
    @Angel You're supposed to run the command on the terminal, not the Python interpreter. – Edric Jan 16 '20 at 10:21
  • https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/ – Ahmet Jan 16 '20 at 10:22
  • The intriguing part is that `python pip install --upgrade pandas` is not in the script as shown – ernest_k Jan 16 '20 at 10:22
  • 1
    Also, delete your `random.py` file. That clashes with a standard library module and causes some of the other problems shown in that output. – user2357112 Jan 16 '20 at 10:24
  • 1
    but after running the pip command through the terminal, it successfully installed panda. (it said install successful but i have to upgrade panda. – Angel Jan 16 '20 at 10:25
  • First install pandas ("pip install --upgrade pandas" from your shell), then launch the script which uses pandas – Don Jan 16 '20 at 10:26
  • 1
    Moreover, you have a "random.py" file in your folder, which masks standard Python library. Name it in a different way – Don Jan 16 '20 at 10:28
  • 1
    @Angel You don't need to upgrade the newly installed package. Can you please run your script and edit your question with only the error? – Henry Harutyunyan Jan 16 '20 at 10:28
  • 1
    Thank you very much.. the code worked. i deleted the random.py file and my coded executed sucessfully. – Angel Jan 16 '20 at 10:29

1 Answers1

6

The thing here is that you have a file called C:\Users\Angel\Documents\Python Basic\random.py, which is imported by /lib/email/utils.py instead of built-in random.

From the docs:

The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory. This is an error unless the replacement is intended.

This error should be fixed if you rename this random.py.

Oleh Rybalchenko
  • 6,998
  • 3
  • 22
  • 36