carandraug / mRNA-localisation-screening

1 stars 3 forks source link

importlib error #4

Closed jstitlow closed 4 years ago

jstitlow commented 4 years ago

I am unable to run the GUI.

(py38) Joshs-MacBook-Pro-6:josh joshtitlow$ python3 questionnaire.py questions answers/ figures/CB_figures_20200201/*.jpg
Traceback (most recent call last):
  File "questionnaire.py", line 215, in <module>
    questions = read_questions(sys.argv[1])
  File "questionnaire.py", line 36, in read_questions
    module = importlib.util.module_from_spec(spec)
  File "<frozen importlib._bootstrap>", line 553, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'

Before that, there is an error in calling importlib:

(py38) Joshs-MacBook-Pro-6:josh joshtitlow$ python3 ../new/new_questionnaire.py questions answers/ figures/CB_figures_20200201/*.jpg
Traceback (most recent call last):
  File "../new/new_questionnaire.py", line 267, in <module>
    main(sys.argv)
  File "../new/new_questionnaire.py", line 259, in main
    questions = read_questions(args.questions_fpath)
  File "../new/new_questionnaire.py", line 47, in read_questions
    spec = importlib.util.spec_from_file_location('questions', filepath)
AttributeError: module 'importlib' has no attribute 'util'

which I solve by adding: from importlib import util

Any idea what causes the 'NoneType' AttributeError? Thanks! j

carandraug commented 4 years ago

Maria had the same problem on her mac. She's using anaconda. The questions file needed to have the .py file extension. Does that fix it for you too?

jstitlow commented 4 years ago

Yes, thanks, but then it doesn't like the questions.py file:

(py38) Joshs-MacBook-Pro-6:josh joshtitlow$ python3 ../new/new_questionnaire.py questions.py answers/ figures/CB_figures_20200201/*.jpg
Traceback (most recent call last):
  File "../new/new_questionnaire.py", line 268, in <module>
    main(sys.argv)
  File "../new/new_questionnaire.py", line 260, in main
    questions = read_questions(args.questions_fpath)
  File "../new/new_questionnaire.py", line 50, in read_questions
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 779, in exec_module
  File "<frozen importlib._bootstrap_external>", line 916, in get_code
  File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "questions.py", line 1
    Is gene expressed in NBs?
       ^
SyntaxError: invalid syntax

How should the questions.py file be formatted? Do you have an example? Mine is like this:

Is gene expressed in NBs?
Obvious transcriptional regulation?
Obvious post-transcriptional regulation?
Is data acceptable?
jstitlow commented 4 years ago

Sorry, instructions are in the header. Here is an example for those who are python impaired:

QUESTIONS = [('Is gene expressed in NBs?', ('no', 'yes')), ('Obvious transcriptional regulation?', ('no', 'yes')), ('Comments', '')]
carandraug commented 4 years ago

By the way, note that the questions file is python code so you can use whatever to generate a variable named QUESTIONS. The change is to accommodate the new requirements from Ilan's group, i.e., where different questions may have different sets of choices and the answer to some questions can be text.

default_answers = ('unsure', 'yes', 'no')

QUESTIONS = [
  ('Level of expression',
   ('none', 'low', 'high')),
  ('Is gene expressed in NBs?',
   default_answers),
  ('Is data acceptable',
   default_answers),
  ('What\'s the problem on this image?',
   'this can be an empty string or the initial answer text'),
]

Because the questions code can be python code, it is possible to end up with a questions file where their order changes between runs. The answers file now also includes the actual question text so that whoever analysis the results can double check. It also helps in preventing a case where different people are scoring with accidentally different or out of date questions files.

carandraug commented 4 years ago

I replaced the use of importlib with exec which should be less sensitive. At least the file extension should no longer matter.