user3025433
user3025433

Reputation: 11

Module imports work in PyCharm, don't work in Python IDLE

Here is the file structure of my project:

data
front_end_ui
- __init__.py
- ui.py

quizlib
- __init__.py
- classes.py
- data_structure.py
- quiz.py
- student.py

Okay, aside from whether this is good programming or not ('tis likely the flying spaghetti monster) the program runs from ui.py, and in PyCharm, the import from quizlib works:

All fine in PyCharm

however in IDLE:

Import failed.

One of the first things as you can see from ui.py's code that happens is that stuff is imported from quizlib's __init__.py (just a couple of absolute directory names that are worked out before the whole program runs, because for the life of me I could not get relative change directory things to work).

Except it doesn't in IDLE. The only way I'm able to get it to work is to copy the entirety of quizlib into front_end_ui. (considering how I coded it I'm not quite sure why it works when I do that) Which if I'm not able to work out why will be an acceptable solution, but the explanation provided along with this project is better off keeping quizlib where it is.

Can somebody please explain this behaviour? For reference, I am using Python 3.4.3, and I'll provide any further details if needed. Thanks in advance.

Upvotes: 1

Views: 596

Answers (1)

laike9m
laike9m

Reputation: 19328

This kind of problem is always due to PyCharm adding project path to PYTHONPATH.

enter image description here

Un-check those options and run again. Results would be the same.

Upvotes: 1

Related Questions