blankme
V2EX  ›  问与答

Python 在 Docker 中无法找到自定义的 Module

  •  
  •   blankme · Aug 11, 2018 · 1204 views
    This topic created in 2856 days ago, the information mentioned may be changed or developed.

    一个简单的文件目录,hello.py 中只有一句话:import my_module

    helloworld
             |
             ----hello.py
             |
             ----my_module
                         |
                         ----__init__.py
    

    在 docker 外运行没有问题,但在 docker 中使用时会报错:ImportError: No module named my_module

    查看过 sys.path 包含工作目录 /helloworld,也尝试过设置 PYTHONPATH,无果。

    不知道是什么原因造成的?

    Supplement 1  ·  Aug 11, 2018
    找到原因了,一个很愚蠢的错误:
    Dockerfile 中使用 ADD ./helloworld/* /helloworld/ 添加文件,这样会将 helloworld 中的目录结构丢弃,所以引发了后续的问题。
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2874 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:08 · PVG 21:08 · LAX 06:08 · JFK 09:08
    ♥ Do have faith in what you're doing.