Unable to use matplotlib

Answered

I have downloaded matplotlib through my python terminal, in addition, I have anaconda installed on my computer. I am trying to execute this code, although the second and fourth line are greyed out, and thus cannot be run. I have tried deleting these lines and the green play button is still grey. 

import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web

style.use('ggplot')

start = dt.datetime(2015, 1, 1)
end = dt.datetime.now()
df = web.DataReader("TSLA", 'morningstar', start, end)
df.reset_index(inplace=True)
df.set_index("Date", inplace=True)
df = df.drop("Symbol", axis=1)

print(df.head())

 

1
5 comments

Hi,

Have you created Run/Debug configuration for your script?

If not, you can right-click the file and choose Run...

0

Yes, but it still says that there is no module named matplotlib, even though I dowloaded it through the terminal.

0

Most likely you installed it to your system interpreter and in PyCharm you use another interpreter (venv apparently).

Follow this tutorial to install matplotlib to your current Project Interpreter https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html

0

I was able to install both Matplotlib and pandas, but it is now giving the the following message when I try to run the code:

2019-05-24 15:27:29.786 python[39319:10342278] -[NSApplication _setup:]: unrecognized selector sent to instance 0x7ffe595d19b0
2019-05-24 15:27:29.795 python[39319:10342278] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x7ffe595d19b0'
*** First throw call stack:
(
0   CoreFoundation                      0x00007fff32addcf9 __exceptionPreprocess + 256
1   libobjc.A.dylib                     0x00007fff5d66da17 objc_exception_throw + 48
2   CoreFoundation                      0x00007fff32b57b06 -[NSObject(NSObject) __retain_OA] + 0
3   CoreFoundation                      0x00007fff32a800ef ___forwarding___ + 1485
4   CoreFoundation                      0x00007fff32a7fa98 _CF_forwarding_prep_0 + 120
5   libtk8.6.dylib                      0x00000001174d631d TkpInit + 413
6   libtk8.6.dylib                      0x000000011742e17e Initialize + 2622
7   _tkinter.cpython-37m-darwin.so      0x00000001147eda0f _tkinter_create + 1183
8   python                              0x0000000104c4e116 _PyMethodDef_RawFastCallKeywords + 230
9   python                              0x0000000104d8ae42 call_function + 306
10  python                              0x0000000104d88aec _PyEval_EvalFrameDefault + 46092
11  python                              0x0000000104d7c49e _PyEval_EvalCodeWithName + 414
12  python                              0x0000000104c4cde7 _PyFunction_FastCallDict + 231
13  python                              0x0000000104ccf381 slot_tp_init + 193
14  python                              0x0000000104cd9361 type_call + 241
15  python                              0x0000000104c4dae3 _PyObject_FastCallKeywords + 179
16  python                              0x0000000104d8aed5 call_function + 453
17  python                              0x0000000104d88be0 _PyEval_EvalFrameDefault + 46336
18  python                              0x0000000104c4d8d5 function_code_fastcall + 117
19  python                              0x0000000104d8adc7 call_function + 183
20  python                              0x0000000104d88aec _PyEval_EvalFrameDefault + 46092
21  python                              0x0000000104d7c49e _PyEval_EvalCodeWithName + 414
22  python                              0x0000000104c4cde7 _PyFunction_FastCallDict + 231
23  python                              0x0000000104c50ce2 method_call + 130
24  python                              0x0000000104c4e752 PyObject_Call + 130
25  python                              0x0000000104d88d58 _PyEval_EvalFrameDefault + 46712
26  python                              0x0000000104d7c49e _PyEval_EvalCodeWithName + 414
27  python                              0x0000000104c4dfe3 _PyFunction_FastCallKeywords + 195
28  python                              0x0000000104d8adc7 call_function + 183
29  python                              0x0000000104d88be0 _PyEval_EvalFrameDefault + 46336
30  python                              0x0000000104c4d8d5 function_code_fastcall + 117
31  python                              0x0000000104d8adc7 call_function + 183
32  python                              0x0000000104d88a56 _PyEval_EvalFrameDefault + 45942
33  python                              0x0000000104c4d8d5 function_code_fastcall + 117
34  python                              0x0000000104d8adc7 call_function + 183
35  python                              0x0000000104d88a56 _PyEval_EvalFrameDefault + 45942
36  python                              0x0000000104d7c49e _PyEval_EvalCodeWithName + 414
37  python                              0x0000000104c4cde7 _PyFunction_FastCallDict + 231
38  python                              0x0000000104d88d58 _PyEval_EvalFrameDefault + 46712
39  python                              0x0000000104d7c49e _PyEval_EvalCodeWithName + 414
40  python                              0x0000000104c4cde7 _PyFunction_FastCallDict + 231
41  python                              0x0000000104d88d58 _PyEval_EvalFrameDefault + 46712
42  python                              0x0000000104d7c49e _PyEval_EvalCodeWithName + 414
43  python                              0x0000000104c4cde7 _PyFunction_FastCallDict + 231
44  python                              0x0000000104ccd46d slot_tp_call + 189
45  python                              0x0000000104c4dae3 _PyObject_FastCallKeywords + 179
46  python                              0x0000000104d8aed5 call_function + 453
47  python                              0x0000000104d88aec _PyEval_EvalFrameDefault + 46092
48  python                              0x0000000104d7c49e _PyEval_EvalCodeWithName + 414
49  python                              0x0000000104ddf9a0 PyRun_FileExFlags + 256
50  python                              0x0000000104ddee17 PyRun_SimpleFileExFlags + 391
51  python                              0x0000000104e0cd3f pymain_main + 9663
52  python                              0x0000000104c2066d main + 125
53  libdyld.dylib                       0x00007fff5ee9b3d5 start + 1
54  ???                                 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
 
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

 

0

Try running it from the system terminal (outside of PyCharm) using the same interpreter. Do you get the same error?

0

Please sign in to leave a comment.