简体   繁体   中英

Import Not Found Error in Docker but not while running locally

I made an 'importTest.py' to troubleshoot. It only has the following code:

try:
    import PackageA.DeviceController
    print("Success")

except ImportError:
    print("fail")

This works locally, but when running in a docker container I get an ImportError . 'PackageA/DeviceController.py' is a local file inside the same directory as 'importTest.py'. (they are both in 'PackageA', which has an empty init .py aswell). When entering the bash from the docker container, and entering 'python3 --> import packageA.DeviceController' this also works but doesn't work when running the script. Does anyone know the reason and how to solve this?

Your local machine has the dependencies installed, but your Docker container does not. You can use a Dockerfile to install the necessary requirements.

您需要在 docker 机器内安装依赖项。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM