The problem is that you're running src.start.go
as if it were a script, i.e. by giving the full path to the python
command:
python src/start/go.py
This makes Python think this go.py
file is a standalone script that isn't part of any package. As defined in the docs (see here, under <script>
), this means that Python will search for modules in the same directory as the script, i.e. src/start/
:
If the script name refers directly to a Python file, the directory
containing that file is added to the start of sys.path
, and the file
is executed as the __main__
module.
But of course, src
is not in src/start/
, so it will throw an error.
The correct way to start a script that is part of a package is to use the -m
switch (reference), which takes a module path as an argument and executes that module as a script (but keeping the current working directory as a module search path):
If this option is given, [...] the current directory
will be added to the start of sys.path
.
So you should use the following to start your program:
python -m src.start.go
Now when src.start.go
tries to import the src
package, it will search in your current working directory (which contains the src/...
tree) and succeed.
As a personal recommendation: don't put runnable scripts inside packages. Use packages only to store all the logic and functionality (functions, classes, constants, etc.) and write a separate script to run your application how you want it to, putting it outside the package. This will save you from these kind of problems, and has also the advantage that you can write several run configurations for the same package by just making a separate startup script for each.