[英]Docker ModuleNotFoundError: No module named 'scipy'
I'm exploring Python through building its Docker image.我正在通过构建 Docker 图像来探索 Python。 I want to use the scipy
library but I'm not able to import it for some reason.我想使用scipy
库,但由于某种原因我无法导入它。 Here are the imports for my __init.py__
file:这是我的__init.py__
文件的导入:
import numpy as np
import scipy.stats as sp
from flask import Flask, g
from flask_restful import Resource, Api, reqparse
My Dockerfile
:我的Dockerfile
:
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./run.py" ]
requirements.txt
: requirements.txt
:
numpy==1.19.0
scipy==0.15.1
Flask==0.12.2
markdown==2.6.11
flask-restful==0.3.6
And finally my docker-compose.yml
:最后是我的docker-compose.yml
:
version: '3.4'
services:
calculator:
build: .
volumes:
- .:/usr/src/app
ports:
- 5000:80
Now when I do a docker-compose up
this is the error:现在,当我执行docker-compose up
这是错误:
calculator | Traceback (most recent call last):
calculator | File "./run.py", line 1, in <module>
calculator | from probability_calculator import app
calculator | File "/usr/src/app/probability_calculator/__init__.py", line 2, in <module>
calculator | import scipy.stats as sp
calculator | ModuleNotFoundError: No module named 'scipy'
I've had a look here but adding those lines to the Dockerfile
still doesn't seem to work.我在这里看过,但将这些行添加到Dockerfile
似乎仍然不起作用。
Answer- requirements.txt
had an old version of scipy
so it wasn't working, I bumped it up to 1.4.1 and it seems to work now. Answer- requirements.txt
有一个旧版本的scipy
所以它不能工作,我把它升级到 1.4.1,它现在似乎工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.