Revolucion for Monica
Revolucion for Monica

Reputation: 3296

Collecting numpy causes docker build to crash

I'm trying to deploy a little python script using Selenium on my GCP Virtual Machine following this tutorial. Unfortunately, I can't pass the requirements.txt when building the container image. Indeed as one can read:

mikempc3@instance-1:~$ sudo docker build --tag my-python-app .
Sending build context to Docker daemon  387.1MB
Step 1/6 : FROM python:alpine3.7
alpine3.7: Pulling from library/python
48ecbb6b270e: Pull complete 
692f29ee68fa: Pull complete 
6439819450d1: Pull complete 
3c7be240f7bf: Pull complete 
ca4b349df8ed: Pull complete 
Digest: sha256:35f6f83ab08f98c727dbefd53738e3b3174a48b4571ccb1910bae480dcdba847
Status: Downloaded newer image for python:alpine3.7
 ---> 00be2573e9f7
Step 2/6 : COPY . /app
 ---> d8ae78db92f8
Step 3/6 : WORKDIR /app
 ---> Running in 3f6269c90e90
Removing intermediate container 3f6269c90e90
 ---> 717897752d1d
Step 4/6 : RUN pip install -r requirements.txt
 ---> Running in 061da28ee5cb
Collecting selenium (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl (904kB)
Collecting pandas (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/6f/29/32ff85413724ffa7cc8d52373f93c2ef1cb197ffd0c7b1b10d36452dd0ca/pandas-1.1.0.tar.gz (5.2MB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'error'
  Complete output from command /usr/local/bin/python /usr/local/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-ou2zb3ns/overlay --no-warn-script-l
ocation --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel Cython>=0.29.16,<3 "numpy==1.15.4; python_version=='3.6' and platform_system!='AIX'" "numpy==1.15.4; 
python_version=='3.7' and platform_system!='AIX'" "numpy==1.17.3; python_version>='3.8' and platform_system!='AIX'" "numpy==1.16.0; python_version=='3.6' and platform_system=='AIX'" "numpy==1.16.0
; python_version=='3.7' and platform_system=='AIX'" "numpy==1.17.3; python_version>='3.8' and platform_system=='AIX'":
  Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version >= "3.8" and platform_system != "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.6" and platform_system == "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.7" and platform_system == "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version >= "3.8" and platform_system == "AIX"' don't match your environment
  Collecting setuptools
    Downloading https://files.pythonhosted.org/packages/8e/11/9e10f1cad4518cb307b484c255cae61e97f05b82f6d536932b1714e01b47/setuptools-49.2.0-py3-none-any.whl (789kB)
  Collecting wheel
    Downloading https://files.pythonhosted.org/packages/8c/23/848298cccf8e40f5bbb59009b32848a4c38f4e7f3364297ab3c3e2e2cd14/wheel-0.34.2-py2.py3-none-any.whl
  Collecting Cython<3,>=0.29.16
    Downloading https://files.pythonhosted.org/packages/ad/4b/9e53bcce3c959fd0db143626e573210bba07be810fe8d7296373948c4183/Cython-0.29.21-py2.py3-none-any.whl (974kB)
  Collecting numpy==1.15.4
    Downloading https://files.pythonhosted.org/packages/2d/80/1809de155bad674b494248bcfca0e49eb4c5d8bee58f26fe7a0dd45029e2/numpy-1.15.4.zip (4.5MB)
  Building wheels for collected packages: numpy
    Building wheel for numpy (setup.py): started
    Building wheel for numpy (setup.py): finished with status 'error'
    Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-800mjafl/numpy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.rea
d().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-q_b64mdo --python-tag cp37:
    Running from numpy source directory.
    blas_opt_info:
    blas_mkl_info:
    customize UnixCCompiler
      libraries mkl_rt not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
  
    blis_info:
    customize UnixCCompiler
      libraries blis not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
  
    openblas_info:
    customize UnixCCompiler
    customize UnixCCompiler
      libraries openblas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
  
    atlas_3_10_blas_threads_info:
    Setting PTATLAS=ATLAS
    customize UnixCCompiler
      libraries tatlas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
  
    atlas_3_10_blas_info:
    customize UnixCCompiler
      libraries satlas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
  
    atlas_blas_threads_info:
    Setting PTATLAS=ATLAS
    customize UnixCCompiler
      libraries ptf77blas,ptcblas,atlas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
  
    atlas_blas_info:
    customize UnixCCompiler
      libraries f77blas,cblas,atlas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
  
    accelerate_info:
      NOT AVAILABLE
  
    /tmp/pip-install-800mjafl/numpy/numpy/distutils/system_info.py:625: UserWarning:
        Atlas (http://math-atlas.sourceforge.net/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [atlas]) or by setting
        the ATLAS environment variable.
      self.calc_info()
    blas_info:
    customize UnixCCompiler
      libraries blas not found in ['/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    ...
        File "/usr/local/lib/python3.7/distutils/core.py", line 148, in setup
          dist.run_commands()
        File "/usr/local/lib/python3.7/distutils/dist.py", line 966, in run_commands
          self.run_command(cmd)
        File "/usr/local/lib/python3.7/distutils/dist.py", line 985, in run_command
          cmd_obj.run()
        File "/tmp/pip-install-800mjafl/numpy/numpy/distutils/command/install.py", line 62, in run
          r = self.setuptools_run()
        File "/tmp/pip-install-800mjafl/numpy/numpy/distutils/command/install.py", line 36, in setuptools_run
          return distutils_install.run(self)
        File "/usr/local/lib/python3.7/distutils/command/install.py", line 545, in run
          self.run_command('build')
        File "/usr/local/lib/python3.7/distutils/cmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "/usr/local/lib/python3.7/distutils/dist.py", line 985, in run_command
          cmd_obj.run()
        File "/tmp/pip-install-800mjafl/numpy/numpy/distutils/command/build.py", line 47, in run
          old_build.run(self)
        File "/usr/local/lib/python3.7/distutils/command/build.py", line 135, in run
          self.run_command(cmd_name)
        File "/usr/local/lib/python3.7/distutils/cmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "/usr/local/lib/python3.7/distutils/dist.py", line 985, in run_command
          cmd_obj.run()
        File "/tmp/pip-install-800mjafl/numpy/numpy/distutils/command/build_src.py", line 148, in run
          self.build_sources()
        File "/tmp/pip-install-800mjafl/numpy/numpy/distutils/command/build_src.py", line 159, in build_sources
          self.build_library_sources(*libname_info)
        File "/tmp/pip-install-800mjafl/numpy/numpy/distutils/command/build_src.py", line 294, in build_library_sources
          sources = self.generate_sources(sources, (lib_name, build_info))
        File "/tmp/pip-install-800mjafl/numpy/numpy/distutils/command/build_src.py", line 377, in generate_sources
          source = func(extension, build_dir)
        File "numpy/core/setup.py", line 666, in get_mathlib_info
          raise RuntimeError("Broken toolchain: cannot link a simple C program")
      RuntimeError: Broken toolchain: cannot link a simple C program
  
      ----------------------------------------
  Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-800mjafl/numpy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\
n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-sgbls4z_/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-ou2zb3ns/overlay -
-compile" failed with error code 1 in /tmp/pip-install-800mjafl/numpy/
  You are using pip version 19.0.1, however version 20.2 is available.
  You should consider upgrading via the 'pip install --upgrade pip' command.
  
  ----------------------------------------
Command "/usr/local/bin/python /usr/local/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-ou2zb3ns/overlay --no-warn-script-location --no-binary :n
one: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel Cython>=0.29.16,<3 "numpy==1.15.4; python_version=='3.6' and platform_system!='AIX'" "numpy==1.15.4; python_version=='3.7' 
and platform_system!='AIX'" "numpy==1.17.3; python_version>='3.8' and platform_system!='AIX'" "numpy==1.16.0; python_version=='3.6' and platform_system=='AIX'" "numpy==1.16.0; python_version=='3.7
' and platform_system=='AIX'" "numpy==1.17.3; python_version>='3.8' and platform_system=='AIX'"" failed with error code 1 in None
You are using pip version 19.0.1, however version 20.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

Here is my requirements.txt file:

selenium
pandas
numpy
collections
json
time
requests

And here is the file I'm trying to contenerize:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import ElementClickInterceptedException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options



import pandas as pd
import numpy as np

from collections import defaultdict
import json

import time

import requests
from requests.exceptions import ConnectionError

# Define Browser Options
chrome_options = Options()
chrome_options.add_argument("--headless") # Hides the browser window

# Reference the local Chromedriver instance
chrome_path = r"C:\Programs\chromedriver.exe"
driver = webdriver.Chrome(executable_path=chrome_path, options=chrome_options)

df = pd.read_csv('path/to/file')    

tradable = []
print(len(df['Ticker']))
for ticker in df['Ticker']:
    print("ticker: ", ticker)
    location = "https://www.etoro.com/markets/" + ticker.lower()
    try:
        request = requests.get(location)
        driver.get(location)
        time.sleep(2)
        current_url = driver.current_url
        if current_url == location:
            tradable.append(ticker)
        else:
            print("no page but request= ", request)
    except ConnectionError:
        print('Ticker isn\'t tradable')
    else:
        tradable.append(ticker)

Here is my Dockerfile:

FROM python:alpine3.7
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 5000
CMD python ./find_tradable.py

Here are my os name and version:

mikempc3@instance-1:~$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Here is my Linux kernel version:

mikempc3@instance-1:~$ uname -r
4.9.0-12-amd64

Update

I'm trying Serhii Rohoza's answer.

I have updated my requirements.txt file, I don't have the same issue but now I have an error when trying the command to build the image from the Dockerfile:

mikempc3@instance-1:~$ sudo docker build --tag my-python-app:1 .
Sending build context to Docker daemon  387.1MB
Step 1/6 : FROM python:python3.7-slim
manifest for python:python3.7-slim not found: manifest unknown: manifest unknown

So I tried:

mikempc3@instance-1:~$ sudo docker pull python:3.7-slim
3.7-slim: Pulling from library/python
6ec8c9369e08: Already exists 
401b5acb42e6: Already exists 
2e487de6656a: Pull complete 
519de614852e: Pull complete 
a3d1a61e090c: Pull complete 
Digest: sha256:47081c7bca01b314e26c64d777970d46b2ad7049601a6f702d424881af9f2738
Status: Downloaded newer image for python:3.7-slim
docker.io/library/python:3.7-slim
mikempc3@instance-1:~$ sudo docker build --tag my-python-app:1 .
Sending build context to Docker daemon  387.1MB
Step 1/6 : FROM python:python3.7-slim
manifest for python:python3.7-slim not found: manifest unknown: manifest unknown

Upvotes: 0

Views: 991

Answers (1)

Serhii
Serhii

Reputation: 4461

To solve your issue you should use Debian based image:

To build Docker image I removed collections (which is deprecated), json (it's built in) and time (it's built in) from requirements.txt and changed Dockerfile:

$ cat Dockerfile 
FROM python:3.7-slim
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 5000
CMD python ./find_tradable.py

$ cat requirements.txt
selenium
pandas
numpy
requests

$ sudo docker build --tag my-python-app:1 .
Sending build context to Docker daemon   5.12kB
Step 1/6 : FROM python:3.7-slim
 ---> c042d3af0838
Step 2/6 : COPY . /app
 ---> ddb4662cd16f
Step 3/6 : WORKDIR /app
 ---> Running in 24e1a60ce53c
Removing intermediate container 24e1a60ce53c
 ---> 5db1f089513b
Step 4/6 : RUN pip install -r requirements.txt
 ---> Running in 5cdde4c11b10
Collecting selenium
  Downloading selenium-3.141.0-py2.py3-none-any.whl (904 kB)
Collecting pandas
  Downloading pandas-1.1.0-cp37-cp37m-manylinux1_x86_64.whl (10.5 MB)
Collecting numpy
  Downloading numpy-1.19.1-cp37-cp37m-manylinux2010_x86_64.whl (14.5 MB)
Collecting requests
  Downloading requests-2.24.0-py2.py3-none-any.whl (61 kB)
Collecting urllib3
  Downloading urllib3-1.25.10-py2.py3-none-any.whl (127 kB)
Collecting python-dateutil>=2.7.3
  Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting pytz>=2017.2
  Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB)
Collecting idna<3,>=2.5
  Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting chardet<4,>=3.0.2
  Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting certifi>=2017.4.17
  Downloading certifi-2020.6.20-py2.py3-none-any.whl (156 kB)
Collecting six>=1.5
  Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
Installing collected packages: urllib3, selenium, six, python-dateutil, numpy, pytz, pandas, idna, chardet, certifi, requests
Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.10 numpy-1.19.1 pandas-1.1.0 python-dateutil-2.8.1 pytz-2020.1 requests-2.24.0 selenium-3.141.0 six-1.15.0 urllib3-1.25.10
WARNING: You are using pip version 20.1.1; however, version 20.2 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Removing intermediate container 5cdde4c11b10
 ---> 94dd7203a37c
Step 5/6 : EXPOSE 5000
 ---> Running in 3f24bb8b62f5
Removing intermediate container 3f24bb8b62f5
 ---> 3bed65d447d6
Step 6/6 : CMD python ./find_tradable.py
 ---> Running in 35c0601f2c70
Removing intermediate container 35c0601f2c70
 ---> af17d0675fee
Successfully built af17d0675fee
Successfully tagged my-python-app:1

As a possible workaround, you can try to install pandas and numpy from packages available in the Alpine repository:

$ cat Dockerfile 
FROM python:alpine3.7
COPY . /app
WORKDIR /app
RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN apk add --update --no-cache libgfortran py3-pandas py3-numpy
ENV PYTHONPATH=/usr/lib/python3.7/site-packages
RUN pip install -r requirements.txt
EXPOSE 5000
CMD python ./find_tradable.py

$ cat requirements.txt
selenium
requests

$ sudo docker build --tag my-python-app:2 .
Sending build context to Docker daemon   5.12kB
Step 1/9 : FROM python:alpine3.7
 ---> 00be2573e9f7
Step 2/9 : COPY . /app
 ---> 2d9fe2cb3266
Step 3/9 : WORKDIR /app
 ---> Running in c106bf69643a
Removing intermediate container c106bf69643a
 ---> 807d1d546864
Step 4/9 : RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
 ---> Running in 77a65a19f776
Removing intermediate container 77a65a19f776
 ---> 940ce2de1711
Step 5/9 : RUN apk add --update --no-cache libgfortran py3-numpy py3-pandas
 ---> Running in 5084ac4055a2
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
fetch http://dl-8.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
(1/11) Installing libgcc (6.4.0-r5)
(2/11) Installing libquadmath (6.4.0-r5)
(3/11) Installing libgfortran (6.4.0-r5)
(4/11) Installing openblas (0.2.19-r3)
(5/11) Installing py3-numpy (1.19.1-r0)
(6/11) Installing python3 (3.6.9-r1)
(7/11) Installing py3-six (1.11.0-r0)
(8/11) Installing py3-dateutil (2.8.1-r0)
(9/11) Installing py3-tz (2017.3-r0)
(10/11) Installing libstdc++ (6.4.0-r5)
(11/11) Installing py3-pandas (1.0.5-r0)
Executing busybox-1.27.2-r11.trigger
OK: 172 MiB in 47 packages
Removing intermediate container 5084ac4055a2
 ---> 3af579bb35da
Step 6/9 : ENV PYTHONPATH=/usr/lib/python3.7/site-packages
 ---> Running in 89513c5c2f02
Removing intermediate container 89513c5c2f02
 ---> 3edc5aa5ef96
Step 7/9 : RUN pip install -r requirements.txt
 ---> Running in a694e49a4fbf
Collecting selenium (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl (904kB)
Collecting requests (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/45/1e/0c169c6a5381e241ba7404532c16a21d86ab872c9bed8bdcd4c423954103/requests-2.24.0-py2.py3-none-any.whl (61kB)
Collecting urllib3 (from selenium->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/9f/f0/a391d1463ebb1b233795cabfc0ef38d3db4442339de68f847026199e69d7/urllib3-1.25.10-py2.py3-none-any.whl (127kB)
Collecting chardet<4,>=3.0.2 (from requests->-r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
Collecting idna<3,>=2.5 (from requests->-r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl (58kB)
Collecting certifi>=2017.4.17 (from requests->-r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/5e/c4/6c4fe722df5343c33226f0b4e0bb042e4dc13483228b4718baf286f86d87/certifi-2020.6.20-py2.py3-none-any.whl (156kB)
Installing collected packages: urllib3, selenium, chardet, idna, certifi, requests
Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.10 requests-2.24.0 selenium-3.141.0 urllib3-1.25.10
You are using pip version 19.0.1, however version 20.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Removing intermediate container a694e49a4fbf
 ---> c6cee0e65a83
Step 8/9 : EXPOSE 5000
 ---> Running in 0a8738c81f82
Removing intermediate container 0a8738c81f82
 ---> 66b223aa513c
Step 9/9 : CMD python ./find_tradable.py
 ---> Running in 3ca56154d699
Removing intermediate container 3ca56154d699
 ---> 3b5e507c7b4b
Successfully built 3b5e507c7b4b
Successfully tagged my-python-app:2

Upvotes: 1

Related Questions