Apr-07-2021, 03:08 PM
Hello!
May i start with saying that the import-module-package system of python is the most abominable feature that I have ever encountered in any language ever.
With that out of the way, i have a project in pycharm with the following structure (underscores to signify tabs...):
CodeStats
__src
_____ __init__.py
_____ code_stats.py
_____ Extension.py
_____ utils.py
__tests
_____ __init__.py
_____ test_one.py
Also in my src folder i have a .bat file named py_run.bat that allows me to run the program from anywhere like this:
py_run code_stats.py
in order for my imports to work I am doing them like this (for example inside utils.py):
from Extension import Extension (file Extension.py has a class named Extension)
and this way the project runs from pycharm and from cmd too
But i made pycharm create a test for me (test_one.py):
this error: ModuleNotFoundError: No module named 'Extension'
if I change the import to "src.Extension import Extension"
the test runs fine, the program from pycharm runs fine but from the cmd it says
ModuleNotFoundError: No module named 'src'
What is wrong with this language? How can it be so stupid and unintuitive for something so simple to work?
How am I supposed to structure my imports?
Thanks in advance.
May i start with saying that the import-module-package system of python is the most abominable feature that I have ever encountered in any language ever.
With that out of the way, i have a project in pycharm with the following structure (underscores to signify tabs...):
CodeStats
__src
_____ __init__.py
_____ code_stats.py
_____ Extension.py
_____ utils.py
__tests
_____ __init__.py
_____ test_one.py
Also in my src folder i have a .bat file named py_run.bat that allows me to run the program from anywhere like this:
py_run code_stats.py
in order for my imports to work I am doing them like this (for example inside utils.py):
from Extension import Extension (file Extension.py has a class named Extension)
and this way the project runs from pycharm and from cmd too
But i made pycharm create a test for me (test_one.py):
from unittest import TestCase class Test(TestCase): def test_contains(self): from src import utils line = ["one", " ", "class", "//"] self.assertTrue(utils.contains(line, "one"))When i run that i get an error on all my imports that are like that: "from Extension import Extension"
this error: ModuleNotFoundError: No module named 'Extension'
if I change the import to "src.Extension import Extension"
the test runs fine, the program from pycharm runs fine but from the cmd it says
ModuleNotFoundError: No module named 'src'
What is wrong with this language? How can it be so stupid and unintuitive for something so simple to work?
How am I supposed to structure my imports?
Thanks in advance.