Pour un projet, j'ai besoin d'importer un fichier DICOM à partir d'une source de données variable. Je travaille sur le projet dans PyCharm car je finirai par itérer sur le code et le produit final sera un programme. L'erreur que je reçois est la suivante:J'ai une erreur lors de l'importation de modules utilisant PyCharm qui ne se produit pas lors de l'utilisation de Jupyter Notebook
2017-10-10 08: 58: 16,307 Python [1010: 26876] - [NSApplication _setup:]: sélecteur non reconnu envoyé à l'instance 0x105154320
2017- 10-10 08: 58: 16.311 Python [1010: 26876] *** App terminaison due à l'exception non interceptée 'NSInvalidArgumentException', raison: '- [NSupplication _setup:]: sélecteur non reconnu envoyé à l'instance 0x105154320'
** * Pile d'appel du premier lancer:
(
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: mettre fin à l'exception de uncaught de type NSException
processus terminé avec le code de sortie 134 (interrompu par le signal 6: SIGABRT)
Le code qui me donne l'erreur est la suivante:
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()
Ce code exact ne produit pas la même erreur lorsqu'il est exécuté en tant que fichier bloc-notes jupyter ou lorsque les importations sont positionnées sur les lignes commentées.
Je ne sais pas pourquoi cela est et j'espère que vous savez pourquoi je reçois cette erreur. Je voudrais avoir les importations du module au sommet du script, parce que, bien, la propreté et d'autres choses.
Merci d'avance!
Merci pour. Cela fonctionne vraiment parfaitement! Et merci pour la réponse rapide. sauveteur! Juste par curiosité, comment aurais-je pu le savoir autrement? Quel est le problème avec le backend "TkAgg"? –
Pas de problème! Content d'avoir aidé. Cela dépend de l'utilisation du matplotlib. Voulez-vous faire apparaître une nouvelle fenêtre ou souhaitez-vous intégrer un intrigue dans une interface graphique? Vous devez sélectionner un backend spécifique pour chaque cas. En fonction de votre système d'exploitation, certains types sont également pris en charge. https://matplotlib.org/faq/usage_faq.html#what-is-a-backend Vous pouvez lire plus sur ce site à propos du backend – anasvaf