Python Relative path and Absolute path

Viewed 313

I am using Pycharm to develop my application, I have created a new class, and I use the following method to call this new class:

(Main() to import this class):

from src.services.log_service import LogService

It works fine in Pycharm, however when I export my code to docker environment, I have the got the following error: enter image description here

My dockerfile is as below:

FROM python:3.8.6
MAINTAINER tester  tester
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app/src/Main.py"]

And my docker directory is as below: enter image description here enter image description here enter image description here

And my folder structure is as below, "log_service.py" is in folder "services"

enter image description here

I tried to change it to relative path, and Pycharm report error when running again:

from .services.log_service import LogService

error:

    from .services.log_service import LogService
ImportError: attempted relative import with no known parent package

Should I use relative path or absolute path? Thanks,

0 Answers
Related