Unable to run Python program in PyCharm
I have created a Python program that runs in Atom (and Terminal) on my Mac, but I'm unable to run the program in PyCharm Edu. I haven't had any problems running other programs in PyCharm.
It seems to be a problem with my installation of matplotlib and/or NumPy. I have installed matplotlib (which included NumPy) using pip3. After the installation the import commands worked successfully (in Terminal).
The code is very short :-
import matplotlib.pyplot as plt
squares = [1, 4, 9, 16, 25]
plt.plot(squares)
plt.show()
While the error message is quite long: -
1
2
3
4
[1, 2, 3, 4, 5]
[2, 4, 6, 8, 10]
Traceback (most recent call last):
File "/Users/Rob/Documents/Rob/Programming/Python/PythonCrashCourse/data_visualisation/mpl_squares.py", line 1, in <module>
import matplotlib.pyplot as plt
File "/Users/Rob/Library/Python/3.5/lib/python/site-packages/matplotlib/__init__.py", line 122, in <module>
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
File "/Users/Rob/Library/Python/3.5/lib/python/site-packages/matplotlib/cbook.py", line 32, in <module>
import numpy as np
File "/Users/Rob/Library/Python/3.5/lib/python/site-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/Users/Rob/Library/Python/3.5/lib/python/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/Users/Rob/Library/Python/3.5/lib/python/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/Users/Rob/Library/Python/3.5/lib/python/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/Users/Rob/Library/Python/3.5/lib/python/site-packages/numpy/core/__init__.py", line 33, in <module>
from . import _internal # for freeze programs
File "/Users/Rob/Library/Python/3.5/lib/python/site-packages/numpy/core/_internal.py", line 15, in <module>
from .numerictypes import object_
File "/Users/Rob/Library/Python/3.5/lib/python/site-packages/numpy/core/numerictypes.py", line 962, in <module>
_register_types()
File "/Users/Rob/Library/Python/3.5/lib/python/site-packages/numpy/core/numerictypes.py", line 958, in _register_types
numbers.Integral.register(integer)
AttributeError: module 'numbers' has no attribute 'Integral'
Process finished with exit code 1
Although I have managed to execute the code successfully in Atom, I would prefer to use PyCharm for my Python work. As you can tell I'm a newbie to Python, but would really appreciate some assistance with this issue. If further information is required, please ask.
TIA.
Rob.
请先登录再写评论。
Hi,
thank you for the report.
Please make sure that you are able to run this script with your project interpreter without error in the system Terminal. Could you please attach a screenshot with it to let me check? Thank you.
The code runs successfully in the Python Console (and Terminal). Below is a screenshot.
Same here, The code runs normally from terminal or python console. But from IDE using Run/Debug buttons not.