Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError only when I use docker

Tags:

python

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.

like image 657
lars Avatar asked Sep 27 '22 19:09

lars


2 Answers

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
like image 111
lingxiao Avatar answered Oct 06 '22 02:10

lingxiao


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.

like image 28
Dennis Persson Avatar answered Oct 06 '22 00:10

Dennis Persson