Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: ModuleNotFoundError: No module named 'traceback' #162

Open
jurgonaut opened this issue Sep 2, 2020 · 6 comments
Open

Python: ModuleNotFoundError: No module named 'traceback' #162

jurgonaut opened this issue Sep 2, 2020 · 6 comments

Comments

@jurgonaut
Copy link

jurgonaut commented Sep 2, 2020

I'm trying to minimize a docker container that uses python and I am getting an error. My Dockerfile looks like this:

FROM amazonlinux:latest

RUN yum install -y make gcc nano openssl-devel bzip2-devel libffi-devel tar zip unzip gzip wget mysql mariadb-devel python-devel sqlite-devel aws-cli \
    && cd /tmp \
    && wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz \
    && tar -xzf Python-3.7.3.tgz \
    && cd Python-3.7.3 \
    && ./configure \
    && make \
    && make altinstall \
    && cd .. \
    && rm -r Python-3.7.3 \
    && rm -r Python-3.7.3.tgz \
    && pip3.7 install scrapy \
    && pip3.7 install mysqlclient \
    && cd /

When I run the container I get the error:

Error processing line 1 of /usr/local/lib/python3.7/site-packages/zope.interface-5.1.0-py3.7-nspkg.pth:

Fatal Python error: initsite: Failed to import the site module
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site.py", line 168, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 580, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site.py", line 586, in <module>
    main()
  File "/usr/local/lib/python3.7/site.py", line 573, in main
    known_paths = addsitepackages(known_paths)
  File "/usr/local/lib/python3.7/site.py", line 349, in addsitepackages
    addsitedir(sitedir, known_paths)
  File "/usr/local/lib/python3.7/site.py", line 207, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "/usr/local/lib/python3.7/site.py", line 178, in addpackage
    import traceback
ModuleNotFoundError: No module named 'traceback'

The command I am using for building the slim container is:

docker-slim build --http-probe=false python-test-slim

Is there a flag I am missing or something similar? I am new to this project so I am not sure if this issue related to docker-slim. But I would be really happy I could get some help because the results amazing.

@kcq
Copy link
Member

kcq commented Sep 2, 2020

Is it your complete Dockerfile @jurgonaut ? Is it just one RUN instruction (and FROM)? This looks like a custom base image... Do you have another image with your application code where you use this custom base image?

@jurgonaut
Copy link
Author

Yes this is all. There is also a COPY which copies a simple python script to test if all the packages are installed. The python script only has a few imports. The base image is an official AWS image. What do you suggest, will it work with another base image?

@kcq
Copy link
Member

kcq commented Sep 3, 2020

@jurgonaut is that COPY instruction in the same Dockerfile? Do you set the ENTRYPOINT and/or CMD instructions? What do they look like if you do? If not, how do you invoke your simple python script in the container?

@jurgonaut
Copy link
Author

@kcq
This is the rest of the Dockerfile

ADD ./entry.sh /usr/local/bin/entry.sh
ADD ./test.py /usr/local/bin/test.py

RUN ["chmod", "+x", "/usr/local/bin/entry.sh"]
RUN ["chmod", "+x", "/usr/local/bin/test.py"]

WORKDIR /usr/local/bin
ENTRYPOINT ["/bin/bash", "/usr/local/bin/entry.sh"]

The file entry.sh content is:

python3.7 ./test.py

And test.py content is:

import MySQLdb

print("SUCCESS")

@michaelcukier
Copy link

@jurgonaut did you find a solution ? I have the exact same problem

@jurgonaut
Copy link
Author

@michaelcukier No I didn't. I haven't work on this since 2020 so I don't know of any recent developments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants