Reputation: 75
Python noob here, apologies if this is has an obvious answer I should know. I'm using Python 3.5.2 via PyCharm in OSX El Capitan and I'm trying to run the following simple script to practise with matplotlib:
import matplotlib.pyplot as plt
year = [1950,1970,1990,2010]
pop = [2.159,3.692,5.263,6.972]
plt.plot(year,pop)
plt.show()
If I execute this line by line in PyCharm's Python console, it works fine. If I execute it as an entire script, I get this error:
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5/Users/Cuckoo/Dropbox/Python/test.py
Traceback (most recent call last):
File "/Users/Cuckoo/Dropbox/Python/test.py", line 1, in <module>
import matplotlib.pyplot as plt
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/__init__.py", line 115, in <module>
import tempfile
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tempfile.py", line 45, in <module>
from random import Random as _Random
ImportError: cannot import name 'Random'
Process finished with exit code 1
Can anyone please explain what has gone wrong and better still, how I can fix it?
Upvotes: 0
Views: 280
Reputation: 2723
This can be caused by having another Python script in your project named random.py
that is overriding the original library named Random.
Try to rename or remove the random.py
file and your script should work from within PyCharm and the command line.
Upvotes: 1