lars
lars

Reputation: 1996

ImportError only when I use docker

I can run a script fine without docker, but when I have to use docker I run it and I get an import error: no module named c.H.

In my docker container, I can do:

python

 import c.H

Everything works fine. But the second I try to run script.py, I get the import error that there is no module named c.H

I do not get this error when I don't use docker.

Upvotes: 5

Views: 9561

Answers (2)

Dennis Persson
Dennis Persson

Reputation: 1114

You are trying to import a module from a package. See this answer to learn the difference between a module and a package. Your problem may be that your package isn't recognized as a package due to a missing __ init.py__ file. Add an empty one to the c directory if you don't already have one.

Upvotes: 1

lingxiao
lingxiao

Reputation: 1224

it's possible that the python version you are using inside the container is different from the python version the script is using. And different version of python may have different packages installed. You could check the python version the script is using from the shebang line. The shebang line should look something like the following:

#!/usr/bin/env python

Upvotes: 3

Related Questions