【发布时间】:2020-12-15 20:47:25
【问题描述】:
所以我在我的程序中使用 websocket。在文件中,我从 websocket 导入 create_connection。
from websocket import create_connection
问题是,当我使用 requirements.txt 从我的 venv 运行它时,pip 安装从 websocket 和 websocket-client 所在的位置,我的程序运行良好。
但是当我做一个 docker 容器时,该 pip 从完全相同的 requirements.txt 文件安装并运行与导入完全相同的脚本,我得到 ImportError: cannot import name 'create_connection' from 'websocket'。
我做错了什么?我的 docker 容器中的其他所有内容都可以正常工作(我正在 requirements.txt 中进行其他安装,例如 pandas 和 numpy),当我在控制台而不是 docker 中运行程序时,程序运行良好。
【问题讨论】:
-
你能发布你的
Dockerfile吗? -
我设法通过添加单独的 RUN pip install websocket 和 RUN pip install websocket-client 来修复它,这很奇怪,因为我仍在为所有其他有效的依赖项执行 RUN pip install -r requirements.txt很好,但是对于 websocket,由于某种原因它不起作用。