2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

jupyterlab(pyzmq)がインストールできない(ERROR: Could not build wheels for pyzmq which use PEP 517 and cannot be installed directly)

Posted at

はじめに

Dockerにjupyterlabを入れた際にエラーが発生したのでまとめたいと思います。
いままでイメージを使ってたので関連のあるライブラリは意識しないでやっていました。

使用したファイル

Dockerfile

FROM python:3.7-alpine

USER root
WORKDIR /app

RUN apk update
RUN apk --no-cache add\
		musl\
		musl-dev\
		libffi-dev\
		gcc\
		g++\
		make\
		gfortran\
		openblas-dev\
		python3-dev

RUN pip install --upgrade pip

RUN pip install\
		jupyterlab==3.1.4

docker-compose.yml

docker-compose.yml
version: '3'
services:
  python3:
    restart: always
    build: .
    container_name: 'jupyter'
    working_dir: '/app'
    volumes:
      - ./app/experiments:/app/
    ports:
      - "8888:8888"
    command: jupyter lab --allow-root

問題

Dockerを利用してJupyterLabの環境を構築委していたときに、jupyterlabをインストールしようとしたときに以下のようなエラーがでました。

(省略)
# 9 142.0   In file included from bundled/zeromq/src/msg.cpp:31:
# 9 142.0   bundled/zeromq/src/compat.hpp:45:1: error: 'size_t strlcpy(char*, const char*, size_t)' was declared 'extern' and later 'static' [-fpermissive]
# 9 142.0      45 | strlcpy (char *dest_, const char *src_, const size_t dest_size_)
# 9 142.0         | ^~~~~~~
# 9 142.0   In file included from bundled/zeromq/src/compat.hpp:34,
# 9 142.0                    from bundled/zeromq/src/msg.cpp:31:
# 9 142.0   /usr/include/string.h:84:8: note: previous declaration of 'size_t strlcpy(char*, const char*, size_t)'
# 9 142.0      84 | size_t strlcpy (char *, const char *, size_t);
# 9 142.0         |        ^~~~~~~
# 9 142.0   error: command 'g++' failed with exit status 1
# 9 142.0   ----------------------------------------
# 9 142.0   ERROR: Failed building wheel for pyzmq
# 9 142.0   Building wheel for tornado (setup.py): started
# 9 142.6   Building wheel for tornado (setup.py): finished with status 'done'
# 9 142.6   Created wheel for tornado: filename=tornado-6.1-cp37-cp37m-linux_x86_64.whl size=416726 sha256=109cbe0d24730aee89135850b791d42dd5b3aac24c941fd55b2757915eb8f282       
# 9 142.6   Stored in directory: /root/.cache/pip/wheels/02/62/2c/f52c662d8ae374c4abda0c13ce432fb58eb1c75281a27b406c
# 9 142.6   Building wheel for argon2-cffi (PEP 517): started
# 9 144.7   Building wheel for argon2-cffi (PEP 517): finished with status 'done'
# 9 144.7   Created wheel for argon2-cffi: filename=argon2_cffi-20.1.0-cp37-abi3-linux_x86_64.whl size=39542 sha256=92306678caa20ec837543367c74db21ffd35edb83bda7bd8e0d5ea8e4239eb29
# 9 144.7   Stored in directory: /root/.cache/pip/wheels/57/12/fd/e064dbe3ee0236aa6c8c6c318a18821413886309a24e5f8fe7
# 9 144.7   Building wheel for pandocfilters (setup.py): started
# 9 145.0   Building wheel for pandocfilters (setup.py): finished with status 'done'
# 9 145.0   Created wheel for pandocfilters: filename=pandocfilters-1.4.3-py3-none-any.whl size=8006 sha256=c1f408203625c41045b6511b0810161100d72af0bc0ca9c5e192504513ea1a58      
# 9 145.0   Stored in directory: /root/.cache/pip/wheels/42/81/34/545dc2fbf0e9137811e901108d37fc04650e81d48f97078000
# 9 145.0 Successfully built MarkupSafe pyrsistent tornado argon2-cffi pandocfilters
# 9 145.0 Failed to build pyzmq
# 9 145.0 ERROR: Could not build wheels for pyzmq which use PEP 517 and cannot be installed directly
------
executor failed running [/bin/sh -c pip install         jupyterlab==3.1.4]: exit code: 1
ERROR: Service 'python3' failed to build : Build failed

以下の行からpyzmqが必要なのに利用できないことがわかります。

ERROR: Could not build wheels for pyzmq which use PEP 517 and cannot be installed directly

解決方法

Pyzmqを入れるためにいろいろネットで調べて試していたところ、以下の記事を見つけました。

How to get rid of cryptography build error?

これを参考にapk add zeromq-devをインストールしました。

変更後のDockerfile

FROM python:3.7-alpine

USER root
WORKDIR /app

RUN apk update
RUN apk --no-cache add\
		musl\
		musl-dev\
		libffi-dev\
		gcc\
		g++\
		make\
		gfortran\
		openblas-dev\
		python3-dev\
		zeromq-dev 

RUN pip install --upgrade pip

RUN pip install\
		jupyterlab==3.1.4

無事インストールができました。

ログに出力されるトークン付きのアドレスにアクセスすることでJupyterLabが利用できるようになります。

おわりに

純粋なPython環境にライブラリいれるのはやはり苦戦します。
おとなしくイメージを使ってやったほうが良いです。

ちなみにこの環境はDockerを知るための教材用の環境として作成しました。

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?