Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble execute project python in bash

Tags:

python

i'm trying execute project python in terminal but appear this error:

(base) hopu@docker-manager1:~/bentoml-airquality$ python src/main.py 
Traceback (most recent call last):
  File "src/main.py", line 7, in <module>
    from src import VERSION, SERVICE, DOCKER_IMAGE_NAME
ModuleNotFoundError: No module named 'src'

The project hierarchy is as follows:

Project hierarchy

If I execute project with any IDE, it works well.

like image 713
Alvaro Avatar asked Sep 09 '26 04:09

Alvaro


1 Answers

Your PYTHONPATH is determined by the directory your python executable is located, not from where you're executing it. For this reason, you should be able to import the files directly, and not from source. You're trying to import from /src, but your path is already in there. Maybe something like this might work:

from . import VERSION, SERVICE, DOCKER_IMAGE_NAME
like image 182
Steinn Hauser Magnússon Avatar answered Sep 11 '26 18:09

Steinn Hauser Magnússon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!