[英]I have an error when importing modules using PyCharm that does not occur when using Jupyter Notebook
For a project I need to import a DICOM file from a variable data source. 对于项目,我需要从可变数据源导入DICOM文件。 I am working on the project in PyCharm as I will eventually iterate on the code and the final product will be a program. 我将在PyCharm中从事该项目,因为我最终将迭代代码,最终产品将是程序。 The error I get is the following: 我得到的错误如下:
2017-10-10 08:58:16.307 Python[1010:26876] -[NSApplication _setup:]: unrecognized selector sent to instance 0x105154320 2017-10-10 08:58:16.307 Python [1010:26876]-[NSApplication _setup:]:无法识别的选择器已发送到实例0x105154320
2017-10-10 08:58:16.311 Python[1010:26876] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x105154320' 2017-10-10 08:58:16.311 Python [1010:26876] ***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[NSApplication _setup:]:无法识别的选择器已发送至实例0x105154320'
*** First throw call stack: ***首先抛出调用堆栈:
( (
0 CoreFoundation 0x00007fff9e92757b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fffb3b801da objc_exception_throw + 48
2 CoreFoundation 0x00007fff9e9a7f14 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00007fff9e89ac93 ___forwarding___ + 1059
4 CoreFoundation 0x00007fff9e89a7e8 _CF_forwarding_prep_0 + 120
5 Tk 0x000000010438cc02 TkpInit + 471
6 Tk 0x00000001043082a9 Tk_Init + 1794
7 _tkinter.cpython-36m-darwin.so 0x00000001041e0dfd Tcl_AppInit + 77
8 _tkinter.cpython-36m-darwin.so 0x00000001041de849 _tkinter_create + 889
9 Python 0x000000010006a7b8 _PyCFunction_FastCallDict + 552
10 Python 0x00000001000f4164 call_function + 612
11 Python 0x00000001000f5b74 _PyEval_EvalFrameDefault + 5604
12 Python 0x00000001000f3500 _PyEval_EvalCodeWithName + 2720
13 Python 0x00000001000f43c7 _PyFunction_FastCallDict + 439
14 Python 0x000000010000ea54 _PyObject_FastCallDict + 356
15 Python 0x000000010000f120 _PyObject_Call_Prepend + 208
16 Python 0x000000010000e443 PyObject_Call + 99
17 Python 0x0000000100089af1 slot_tp_init + 81
18 Python 0x00000001000802b4 type_call + 212
19 Python 0x000000010000e9a4 _PyObject_FastCallDict + 180
20 Python 0x00000001000f3fa5 call_function + 165
21 Python 0x00000001000f5b74 _PyEval_EvalFrameDefault + 5604
22 Python 0x00000001000f3eae fast_function + 606
23 Python 0x00000001000f414b call_function + 587
24 Python 0x00000001000f5b74 _PyEval_EvalFrameDefault + 5604
25 Python 0x00000001000f3500 _PyEval_EvalCodeWithName + 2720
26 Python 0x00000001000f3d2b fast_function + 219
27 Python 0x00000001000f414b call_function + 587
28 Python 0x00000001000f5b74 _PyEval_EvalFrameDefault + 5604
29 Python 0x00000001000f3500 _PyEval_EvalCodeWithName + 2720
30 Python 0x00000001000f43c7 _PyFunction_FastCallDict + 439
31 Python 0x000000010000ea54 _PyObject_FastCallDict + 356
32 Python 0x000000010000f120 _PyObject_Call_Prepend + 208
33 Python 0x000000010000e443 PyObject_Call + 99
34 Python 0x0000000100089af1 slot_tp_init + 81
35 Python 0x00000001000802b4 type_call + 212
36 Python 0x000000010000e9a4 _PyObject_FastCallDict + 180
37 Python 0x00000001000f3fa5 call_function + 165
38 Python 0x00000001000f5b74 _PyEval_EvalFrameDefault + 5604
39 Python 0x00000001000f3500 _PyEval_EvalCodeWithName + 2720
40 Python 0x00000001000f3d2b fast_function + 219
41 Python 0x00000001000f414b call_function + 587
42 Python 0x00000001000f5b74 _PyEval_EvalFrameDefault + 5604
43 Python 0x00000001000f3500 _PyEval_EvalCodeWithName + 2720
44 Python 0x00000001000f3d2b fast_function + 219
45 Python 0x00000001000f414b call_function + 587
46 Python 0x00000001000f5b74 _PyEval_EvalFrameDefault + 5604
47 Python 0x00000001000f3500 _PyEval_EvalCodeWithName + 2720
48 Python 0x00000001000f36a4 PyEval_EvalCode + 100
49 Python 0x000000010013000e PyRun_FileExFlags + 206
50 Python 0x00000001001302af PyRun_SimpleFileExFlags + 447
51 Python 0x0000000100149b3a Py_Main + 3914
52 Python 0x0000000100000dfe Python + 3582
53 Python 0x0000000100000c34 Python + 3124
54 ??? 0x0000000000000002 0x0 + 2
) libc++abi.dylib: terminating with uncaught exception of type NSException )libc ++ abi.dylib:以类型为NSException的未捕获异常终止
Process finished with exit code 134 (interrupted by signal 6: SIGABRT) 退出代码为134的过程结束(被信号6:SIGABRT中断)
The code that gives me the error is the following: 给我错误的代码如下:
import pydicom
from tkinter import filedialog
from matplotlib import pylab
"""Get fileName"""
#from tkinter import filedialog
filename = filedialog.askopenfilename()
"""Import DICOM File"""
#import pydicom
df = pydicom.read_file(filename)
dim = df.pixel_array
"""Show DICOM Image"""
#from matplotlib import pylab
pylab.imshow(dim, cmap="gray")
pylab.show()
This exact code does not produce the same error when run as a jupyter notebook file, or when the imports are positioned at the commented lines. 当作为jupyter笔记本文件运行时,或者当导入位于注释行时,此确切的代码不会产生相同的错误。
I have no clue why this is and I am hoping you may know why I am getting this error. 我不知道为什么会这样,我希望您可能知道为什么我会收到此错误。 I would like to have the module imports at the top of the script, because, well, neatness and stuff. 我想将模块导入放在脚本的顶部,因为,很整洁。
Thanks in advance! 提前致谢!
I think it is an issue with the matplotlib TkAgg backend. 我认为这与matplotlib TkAgg后端有关。 Try the following for the matplotlib library 对于matplotlib库尝试以下操作
import matplotlib
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.