F
F
Fortage2018-09-14 08:11:08
Python
Fortage, 2018-09-14 08:11:08

Doesn't Run Python project via console with error ModuleNotFoundError: No module named?

Doesn't Launch Python project via console with error
from Chip88.Chip8 import *
ModuleNotFoundError: No module named 'Chip88'
If I launch via Pycharm everything starts fine.
The project tree is:
-Chip8
-chip8/Chip88
-chip8/Chip88/main.py
-chip8/Chip88/Interface.py
-chip8/Chip88/Chip8.py
-chip8/Chip88/__init__.py
-chip8/__init__.py
On startup main.py swears at the Chip8 file when the line from Chip88.Chip8 import *
How to fix?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DDDsa, 2018-09-14
@Fortage

The file you run must be in the root of the project, otherwise there is no point in the package structure you created. So the tree should look like this:

-chip8/
-chip8/chip88/
-chip8/chip88/interface.py
-chip8/chip88/chip8.py
-chip8/chip88/__init__.py
-chip8/main.py

Now you have a project folder chip8, it contains the main file main.pyand one package chip88. Then in the main.py file, the import from chip8.py should look like this: By the way, this is an anti-pattern, so it's better not to do it. Import only what you intend to use in this module. Also note that I've removed capital letters from all file and folder names. In python, it is customary to start only class names with a capital letter *** What to read. https://chrisyeh96.github.io/2017/08/08/definitive... - about imports. Imports in python only look simple, in fact, there are important nuances that are better to understand. https://www.python.org/dev/peps/pep-0366/
— pep exactly for your case. Useful to understand why your option is not working.
https://www.python.org/dev/peps/pep-0008/ - Well, pep8. Any self-respecting pythonist should know this document by heart. It's all about the naming rule in python and other accepted coding conventions and more.

A
Artem, 2018-09-14
@ulkoart

from Chip88.сhip8 import *

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question