Reputation: 4827
I have been running Anaconda python for several years on my iMac. I'm using it mostly for numerical calculation so I use numpy in most of my scripts. Recently it seems to have quit working. I updated Anaconda and ran conda install numpy
. However when I try to run simple codes using numpy I get error messages and the code ends. To get to the basics, I ran my Hello_World.py program and it ran fine.
print ("Hello World")
x = 0
print(np.cos(x))
Next I added 1 line and changed print(x) to print(cos(x)) so that code reads:
import numpy as np
print ("Hello World")
x = 0
print(np.cos(x))
These are the only changes but now I get the following error messages:
Traceback (most recent call last): File "hello_World.py", line 1, in import numpy as py File "/Users/johnhanly/opt/anaconda3/lib/python3.8/site-packages/numpy/init.py", line 152, in from . import random File "/Users/johnhanly/opt/anaconda3/lib/python3.8/site-packages/numpy/random/init.py", line 181, in from . import _pickle File "/Users/johnhanly/opt/anaconda3/lib/python3.8/site-packages/numpy/random/_pickle.py", line 1, in 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 "/Users/johnhanly/opt/anaconda3/lib/python3.8/secrets.py", line 20, in from random import SystemRandom File "/Users/johnhanly/random.py", line 2, in x = random.randint(100) AttributeError: partially initialized module 'numpy.random' has no attribute 'randint' (most likely due to a circular import)
I am running the codes from the terminal by typing
python hello_world.py
Why does numpy cause my programs to crash.
BTW, the code with numpy runs using Spyder but crashes using the command line.
Upvotes: 0
Views: 1034
Reputation: 6758
You have a file called random.py
in location "/Users/johnhanly/random.py"
python is trying to import that one rather than numpy so please delete or rename the file.
Upvotes: 4