简体   繁体   中英

No module named 'projecta' when running in docker but works in PyCharm

I have a Python Flask application setup in PyCharm. The folder structure for the project is as follows:

- README.md
- .gitignore
- projecta/
      - __init__.py
      - src/__init__.py
      - src/app.py
      - src/api/hello.py
      - src/service/helloService.py
      - Dockerfile
      - requirements.txt 
- projectb/

In my dockerfile, I have the following content:

FROM python:3.6
RUN mkdir /projecta
WORKDIR /projecta
ADD . /projecta/
RUN pip install -r requirements.txt
EXPOSE 8000
CMD ["python", "/projecta/src/app.py"]

In my PyCharm, I run it as a Python Configuration with script path as path-to-folder/projecta/src/app.py and working directory as path-to-folder/projecta/src .

When I run from PyCharm, things run normally without any issues. But when I run from docker using docker run -d --name aa:0.0.2 and building using docker build -ta:0.0.2 . , it gives the following error:

Traceback (most recent call last):

File "/projecta/src/app.py", line 3, in <module>

from projecta.src.api import api

ModuleNotFoundError: No module named 'projecta'

I am not expert in Python/Flask nor Docker. Can someone point out what is wrong here?

try from .api import api in line 3 of app.py

It will not run in pycharm then but will go well in docker

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM