-2
FROM python:3.8-slim-buster
WORKDIR /app
COPY requirements.txt .
RUN pip3 install -r requirements.txt
COPY . .
ENTRYPOINT [ "python3" ]    
CMD [ "main.py" ]

Error:

Traceback (most recent call last):
  File "main.py", line 6, in <module>
    from passbook.models import Pass, Barcode, StoreCard, Location
  File "/app/passbook/models.py", line 8, in <module>
    from M2Crypto import SMIME
ModuleNotFoundError: No module named 'M2Crypto'
tobias_k
  • 81,265
  • 12
  • 120
  • 179
  • even I tried virtual env, here my docker file for the same FROM python:3.8-slim-buster RUN virtualenv --system-site-packages venv RUN source /venv/bin/activate RUN mkdir /app WORKDIR /app COPY requirements.txt /app/ RUN pip3 install --ignore-installed -r requirements.txt COPY . . CMD [ "Python3" , "-m" , "main.py" ] – Shyam Richard Jun 22 '22 at 10:20
  • Can you replicate the error with a local installation or venv of your requirements.txt without a Dockerfile? – ValentinB Jun 22 '22 at 10:23
  • [2/8] RUN virtualenv --system-site-packages venv: #6 0.228 /bin/sh: 1: virtualenv: not found ------executor failed running [/bin/sh -c virtualenv --system-site-packages venv]: exit code: 127 – Shyam Richard Jun 22 '22 at 10:33
  • this the error i'm getting when I try to use venv – Shyam Richard Jun 22 '22 at 10:33
  • For what you're showing, trying to use a virtual environment inside Docker will be unnecessarily complicated. (`source` is not a standard shell command, and the equivalent `.` doesn't "stick" beyond its current `RUN` command, and the Docker image itself is isolation from other Pythons.) – David Maze Jun 22 '22 at 10:51
  • Where do you expect the `M2Crypto` import to come from? Is it a library listed in your `requirements.txt` file (and if so, can you [edit] the question to show that)? Or part of your application source (and if so, can you [edit] the question to show that)? How are you running the container? – David Maze Jun 22 '22 at 10:52

1 Answers1

-1

Installing and running the venv would be the answer here, since the error message tells you, it cant find venv.

Try something like this:

- pip install virutalenv
- virtualenv ~/eb-virt
- source ~/eb-virt/bin/activate
ValentinB
  • 71
  • 7
  • You don't generally need a virtual environment in Docker since a container is isolation from other Pythons (some setups using multi-stage builds use it successfully). The [`venv` tool](https://docs.python.org/3/library/venv.html) has been built into Python for a long time and you don't need to separately install it. `source` isn't a standard shell command and won't work on _e.g._ Alpine Linux; the `activate` script doesn't work well in Docker. [Activate python virtualenv in Dockerfile](https://stackoverflow.com/questions/48561981/activate-python-virtualenv-in-dockerfile) has more details. – David Maze Jun 22 '22 at 10:55
  • It was meant for local testing, forgot to remove the RUN command, like i've mentioned in my comment above. – ValentinB Jun 22 '22 at 11:34
  • thank you, but I'm creating docker image for python, while docker run i'm getting the error like Traceback (most recent call last): File "main.py", line 6, in from models import Pass, Barcode, StoreCard, Location File "/app/models.py", line 8, in from M2Crypto import SMIME – Shyam Richard Jun 22 '22 at 12:14