Home > Net >  Import own python files in docker container - Import Error
Import own python files in docker container - Import Error

Time:07-13

I am having a flask server in a docker container and wanna actually import some of my own python files also on this server. Everytime I am trying this I am getting a "ImportError: cannot import name 'ACCESS_DEFAULT'.

I found already question about a similiar issue here (Importing python file in docker container) on stackoverflow but I am struggeling to get it working.

The error statement looks like this:

Attaching to g2_app_1
app_1  | Traceback (most recent call last):
app_1  |   File "app.py", line 4, in <module>
app_1  |     from inferenceMachine import calculateRouteAndNavigateMBot
app_1  |   File "/environmentservice/inferenceMachine.py", line 3, in <module>
app_1  |     from mBotControlPy.pathToNavigationConverting import convertPathToNavigationCommands
app_1  |   File "/environmentservice/mBotControlPy/pathToNavigationConverting.py", line 3, in <module>
app_1  |     from mmap import ACCESS_DEFAULT
app_1  | ImportError: cannot import name 'ACCESS_DEFAULT'
g2_app_1 exited with code 1

My fow my project structure looks like:

|-Dockerfile
|-app.py
|-requirements.txt
|-inferenceMachine.py
|_
   mBotControlPy
   |-mBotControl.py
   |-pathToNavigationConverting.py
|_
   intelligentPathFindingPy
   |-pathFindingAlgorithm.py

And my Dockerfile configuration is here:

# start from base

#FROM ubuntu:18.04
FROM python:3.6.8-alpine

LABEL maintainer="Group2"

#RUN apt-get update -y && \
#    apt-get install -y python-pip python-dev



COPY ./requirements.txt /environmentservice/requirements.txt

#ADD intelligentPathFindingPy /environmentservice/intelligentPathFindingPy
#ADD mBotControlPy /environmentservice/mBotControlPy
#COPY ./inferenceMachine.py /environmentservice/inferenceMachine.py
#COPY ./app.py /environmentservice/app.py

WORKDIR /environmentservice

RUN pip install -r requirements.txt

COPY . /environmentservice

CMD [ "python", "./environmentservice/app.py" ]

Do you have some hints what I am doing wrong in this case? I assume it is having something to do with the structure of the files in the Dockerfile.

CodePudding user response:

You are using a Python 3.6 image but the ACCESS_DEFAULT constant was added to the mmap module in Python 3.7.

From the docs:

Changed in version 3.7: Added ACCESS_DEFAULT constant

Either change the image to a Python 3.7 image:

FROM python:3.7-alpine

or don't use mmap.ACCESS_DEFAULT.

CodePudding user response:

You are using python-3.6.8 but ACCESS_DEFAULT has been added to mmap in Python 3.7. Try to update Python version in the Dockerfile (FROM line)

  • Related