简体   繁体   English

运行Docker映像时出错。 没有显示名为cv2,request,boto3的模块

[英]Error in Running Docker image. Showing no module named cv2,request,boto3

#!/usr/bin/env python
from time import sleep
import datetime
import os
import shutil
import cv2
import io
import numpy as np
import glob
from threading import Thread
import urllib2
import requests
import json
import boto3
import datetime 

I am not able to run my script on docker as I am not able to run modules like cv2 , numpy , requests and boto3 . 我无法在cv2上运行脚本,因为我无法运行cv2numpyrequestsboto3 It works perfectly when I run it on terminal but when I run it as docker image it is showing error that no modules named ... How can i make it run on my docker? 当我在终端上运行它时,它可以正常工作,但是当我将它作为docker映像运行时,它显示错误,提示没有模块命名。

Dockerfile: Dockerfile:

FROM resin/raspberry-pi-python:latest
RUN mkdir /myscript
WORKDIR /myscript
COPY capturing.py .
CMD ["/myscript/capturing.py", "-flag"]

You can run your container: 您可以运行容器:

docker run -it <image_name>

and execute the following command in python console that will install specified packages in your container: 并在python控制台中执行以下命令,该命令将在您的容器中安装指定的软件包:

import os
os.system("pip install --upgrade pip")
os.system("pip install numpy requests boto3 opencv-python")

You will see: 你会看见:

Collecting numpy
  Downloading numpy-1.13.3-cp36-cp36m-manylinux1_x86_64.whl (17.0MB)
    100% |████████████████████████████████| 17.0MB 124kB/s 
Collecting requests
  Downloading requests-2.18.4-py2.py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 4.8MB/s 
Collecting boto3
  Downloading boto3-1.4.7-py2.py3-none-any.whl (128kB)
    100% |████████████████████████████████| 133kB 3.4MB/s 
Collecting opencv-python
  Downloading opencv_python-3.3.0.10-cp36-cp36m-manylinux1_x86_64.whl (15.4MB)
    100% |████████████████████████████████| 15.5MB 126kB/s 
Collecting certifi>=2017.4.17 (from requests)
  Downloading certifi-2017.11.5-py2.py3-none-any.whl (330kB)
    100% |████████████████████████████████| 337kB 2.9MB/s 
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 4.4MB/s 
Collecting idna<2.7,>=2.5 (from requests)
  Downloading idna-2.6-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 6.0MB/s 
Collecting urllib3<1.23,>=1.21.1 (from requests)
  Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)
    100% |████████████████████████████████| 133kB 3.4MB/s 
Collecting jmespath<1.0.0,>=0.7.1 (from boto3)
  Downloading jmespath-0.9.3-py2.py3-none-any.whl
Collecting s3transfer<0.2.0,>=0.1.10 (from boto3)
  Downloading s3transfer-0.1.11-py2.py3-none-any.whl (54kB)
    100% |████████████████████████████████| 61kB 6.4MB/s 
Collecting botocore<1.8.0,>=1.7.0 (from boto3)
  Downloading botocore-1.7.46-py2.py3-none-any.whl (3.7MB)
    100% |████████████████████████████████| 3.7MB 535kB/s 
Collecting python-dateutil<3.0.0,>=2.1 (from botocore<1.8.0,>=1.7.0->boto3)
  Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
    100% |████████████████████████████████| 194kB 3.1MB/s 
Collecting docutils>=0.10 (from botocore<1.8.0,>=1.7.0->boto3)
  Downloading docutils-0.14-py3-none-any.whl (543kB)
    100% |████████████████████████████████| 552kB 2.2MB/s 
Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1->botocore<1.8.0,>=1.7.0->boto3)
  Downloading six-1.11.0-py2.py3-none-any.whl
Installing collected packages: numpy, certifi, chardet, idna, urllib3, requests, jmespath, six, python-dateutil, docutils, botocore, s3transfer, boto3, opencv-python
Successfully installed boto3-1.4.7 botocore-1.7.46 certifi-2017.11.5 chardet-3.0.4 docutils-0.14 idna-2.6 jmespath-0.9.3 numpy-1.13.3 opencv-python-3.3.0.10 python-dateutil-2.6.1 requests-2.18.4 s3transfer-0.1.11 six-1.11.0 urllib3-1.22

So all is ok. 一切都很好。 I tested it in container built using FROM python:latest Dockerfile. 我在使用FROM python:latest Dockerfile构建的容器中对其进行了测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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