90856


**問題：python2にnumpyを追加できない。**

[code]

    $ pip2 install numpy 2>pip2.err
    Defaulting to user installation because normal site-packages is not writeable
    Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
    Collecting numpy
      Using cached numpy-1.16.6.zip (5.1 MB)
    Building wheels for collected packages: numpy
      Building wheel for numpy (setup.py) ... error
      Running setup.py clean for numpy
    Failed to build numpy
    Installing collected packages: numpy
        Running setup.py install for numpy ... error
    
[/code]

実行環境：Raspberry pi os release 11にpython2を導入しています。

[code]

    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Debian
    Description:    Debian GNU/Linux 11 (bullseye)
    Release:        11
    Codename:       bullseye
    
    $ python2 --version
    Python 2.7.18
    $ pip2 --version
    pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
    
[/code]

エラーの内容：pip2.errは714行あるため途中省略とし、最初の200行と最後の100行を掲載します。

[code]

    $ head -200 pip2.err
    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
      ERROR: Command errored out with exit status 1:
       command: /usr/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-eFE3f7/numpy/setup.py'"'"'; __file__='"'"'/tmp/pip-install-eFE3f7/numpy/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-EuYogG
           cwd: /tmp/pip-install-eFE3f7/numpy/
      Complete output (346 lines):
      Running from numpy source directory.
      blas_opt_info:
      blas_mkl_info:
      customize UnixCCompiler
        libraries mkl_rt not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
        NOT AVAILABLE
    
      blis_info:
      customize UnixCCompiler
        libraries blis not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
        NOT AVAILABLE
    
      openblas_info:
      customize UnixCCompiler
      customize UnixCCompiler
        libraries openblas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
        NOT AVAILABLE
    
      atlas_3_10_blas_threads_info:
      Setting PTATLAS=ATLAS
      customize UnixCCompiler
        libraries tatlas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
        NOT AVAILABLE
    
      atlas_3_10_blas_info:
      customize UnixCCompiler
        libraries satlas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
        NOT AVAILABLE
    
      atlas_blas_threads_info:
      Setting PTATLAS=ATLAS
      customize UnixCCompiler
        libraries ptf77blas,ptcblas,atlas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
        NOT AVAILABLE
    
      atlas_blas_info:
      customize UnixCCompiler
        libraries f77blas,cblas,atlas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
        NOT AVAILABLE
    
      accelerate_info:
        NOT AVAILABLE
    
      /tmp/pip-install-eFE3f7/numpy/numpy/distutils/system_info.py:639: 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
      customize UnixCCompiler
      C compiler: aarch64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -ffile-prefix-map=/build/python2.7-6vbNIT/python2.7-2.7.18=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC
    
      creating /tmp/tmpqQ3oa0/tmp
      creating /tmp/tmpqQ3oa0/tmp/tmpqQ3oa0
      compile options: '-I/usr/local/include -I/usr/include -c'
      aarch64-linux-gnu-gcc: /tmp/tmpqQ3oa0/source.c
      aarch64-linux-gnu-gcc -pthread /tmp/tmpqQ3oa0/tmp/tmpqQ3oa0/source.o -L/usr/lib/aarch64-linux-gnu -lcblas -o /tmp/tmpqQ3oa0/a.out
      /usr/bin/ld: -lcblas が見つかりません
      collect2: error: ld returned 1 exit status
      aarch64-linux-gnu-gcc -pthread /tmp/tmpqQ3oa0/tmp/tmpqQ3oa0/source.o -L/usr/lib/aarch64-linux-gnu -lblas -o /tmp/tmpqQ3oa0/a.out
      customize UnixCCompiler
        FOUND:
          libraries = ['blas', 'blas']
          library_dirs = ['/usr/lib/aarch64-linux-gnu']
          language = c
          define_macros = [('HAVE_CBLAS', None)]
          include_dirs = ['/usr/local/include', '/usr/include']
    
        FOUND:
          libraries = ['blas', 'blas']
          library_dirs = ['/usr/lib/aarch64-linux-gnu']
          define_macros = [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)]
          language = c
          include_dirs = ['/usr/local/include', '/usr/include']
    
      /bin/sh: 1: svnversion: not found
      non-existing path in 'numpy/distutils': 'site.cfg'
      lapack_opt_info:
      lapack_mkl_info:
      customize UnixCCompiler
        libraries mkl_rt not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
        NOT AVAILABLE
    
      openblas_lapack_info:
      customize UnixCCompiler
      customize UnixCCompiler
        libraries openblas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
        NOT AVAILABLE
    
      openblas_clapack_info:
      customize UnixCCompiler
      customize UnixCCompiler
        libraries openblas,lapack not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
        NOT AVAILABLE
    
      atlas_3_10_threads_info:
      Setting PTATLAS=ATLAS
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries tatlas,tatlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib
      customize UnixCCompiler
        libraries tatlas,tatlas not found in /usr/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib/aarch64-linux-gnu
      customize UnixCCompiler
        libraries tatlas,tatlas not found in /usr/lib/aarch64-linux-gnu
      <class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
        NOT AVAILABLE
    
      atlas_3_10_info:
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries satlas,satlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib
      customize UnixCCompiler
        libraries satlas,satlas not found in /usr/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib/aarch64-linux-gnu
      customize UnixCCompiler
        libraries satlas,satlas not found in /usr/lib/aarch64-linux-gnu
      <class 'numpy.distutils.system_info.atlas_3_10_info'>
        NOT AVAILABLE
    
      atlas_threads_info:
      Setting PTATLAS=ATLAS
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries ptf77blas,ptcblas,atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib
      customize UnixCCompiler
        libraries ptf77blas,ptcblas,atlas not found in /usr/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib/aarch64-linux-gnu
      customize UnixCCompiler
        libraries ptf77blas,ptcblas,atlas not found in /usr/lib/aarch64-linux-gnu
      <class 'numpy.distutils.system_info.atlas_threads_info'>
        NOT AVAILABLE
    
      atlas_info:
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries f77blas,cblas,atlas not found in /usr/local/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib
      customize UnixCCompiler
        libraries f77blas,cblas,atlas not found in /usr/lib
      customize UnixCCompiler
        libraries lapack_atlas not found in /usr/lib/aarch64-linux-gnu
      customize UnixCCompiler
        libraries f77blas,cblas,atlas not found in /usr/lib/aarch64-linux-gnu
      <class 'numpy.distutils.system_info.atlas_info'>
        NOT AVAILABLE
    
      lapack_info:
      customize UnixCCompiler
        libraries lapack not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/aarch64-linux-gnu']
        NOT AVAILABLE
    
      /tmp/pip-install-eFE3f7/numpy/numpy/distutils/system_info.py:639: UserWarning:
          Lapack (http://www.netlib.org/lapack/) libraries not found.
          Directories to search for the libraries can be specified in the
          numpy/distutils/site.cfg file (section [lapack]) or by setting
          the LAPACK environment variable.
        self.calc_info()
      lapack_src_info:
        NOT AVAILABLE
    
      /tmp/pip-install-eFE3f7/numpy/numpy/distutils/system_info.py:639: UserWarning:
          Lapack (http://www.netlib.org/lapack/) sources not found.
          Directories to search for the sources can be specified in the
          numpy/distutils/site.cfg file (section [lapack_src]) or by setting
          the LAPACK_SRC environment variable.
        self.calc_info()
        NOT AVAILABLE
    
      /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'define_macros'
        warnings.warn(msg)
      running bdist_wheel
      running build
      running config_cc
      unifing config_cc, config, build_clib, build_ext, build commands --compiler options
      running config_fc
      unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
      running build_src
      build_src
    
        　　・・・途中省略
    
        $ tail -100 pip2.err
        aarch64-linux-gnu-gcc -pthread _configtest.o -o _configtest
        success!
        removing: _configtest.c _configtest.o _configtest.o.d _configtest
        C compiler: aarch64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -ffile-prefix-map=/build/python2.7-6vbNIT/python2.7-2.7.18=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC
    
        compile options: '-Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/usr/include/python2.7 -c'
        aarch64-linux-gnu-gcc: _configtest.c
        _configtest.c:1:5: warning: conflicting types for built-in function ‘exp’; expected ‘double(double)’ [-Wbuiltin-declaration-mismatch]
            1 | int exp (void);
              |     ^~~
        _configtest.c:1:1: note: ‘exp’ is declared in header ‘<math.h>’
          +++ |+#include <math.h>
            1 | int exp (void);
        aarch64-linux-gnu-gcc -pthread _configtest.o -o _configtest
        /usr/bin/ld: _configtest.o: in function `main':
        /tmp/pip-install-eFE3f7/numpy/_configtest.c:6: undefined reference to `exp'
        collect2: error: ld returned 1 exit status
        failure.
        removing: _configtest.c _configtest.o _configtest.o.d
        C compiler: aarch64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -ffile-prefix-map=/build/python2.7-6vbNIT/python2.7-2.7.18=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC
    
        compile options: '-Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/usr/include/python2.7 -c'
        aarch64-linux-gnu-gcc: _configtest.c
        _configtest.c:1:5: warning: conflicting types for built-in function ‘exp’; expected ‘double(double)’ [-Wbuiltin-declaration-mismatch]
            1 | int exp (void);
              |     ^~~
        _configtest.c:1:1: note: ‘exp’ is declared in header ‘<math.h>’
          +++ |+#include <math.h>
            1 | int exp (void);
        aarch64-linux-gnu-gcc -pthread _configtest.o -lm -o _configtest
        success!
        removing: _configtest.c _configtest.o _configtest.o.d _configtest
          adding 'build/src.linux-aarch64-2.7/numpy/core/src/npymath' to include_dirs.
        None - nothing done with h_files = ['build/src.linux-aarch64-2.7/numpy/core/src/npymath/npy_math_internal.h']
        building library "npysort" sources
          adding 'build/src.linux-aarch64-2.7/numpy/core/src/common' to include_dirs.
        None - nothing done with h_files = ['build/src.linux-aarch64-2.7/numpy/core/src/common/npy_sort.h', 'build/src.linux-aarch64-2.7/numpy/core/src/common/npy_partition.h', 'build/src.linux-aarch64-2.7/numpy/core/src/common/npy_binsearch.h']
        building extension "numpy.core._dummy" sources
        Generating build/src.linux-aarch64-2.7/numpy/core/include/numpy/config.h
        C compiler: aarch64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -ffile-prefix-map=/build/python2.7-6vbNIT/python2.7-2.7.18=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC
    
        compile options: '-Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/usr/include/python2.7 -c'
        aarch64-linux-gnu-gcc: _configtest.c
        _configtest.c:1:10: fatal error: Python.h: そのようなファイルやディレクトリ はありません
            1 | #include <Python.h>
              |          ^~~~~~~~~~
        compilation terminated.
        failure.
        removing: _configtest.c _configtest.o
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/tmp/pip-install-eFE3f7/numpy/setup.py", line 419, in <module>
            setup_package()
          File "/tmp/pip-install-eFE3f7/numpy/setup.py", line 411, in setup_package
            setup(**metadata)
          File "/tmp/pip-install-eFE3f7/numpy/numpy/distutils/core.py", line 171, in setup
            return old_setup(**new_attr)
          File "/usr/local/lib/python2.7/dist-packages/setuptools/__init__.py", line 162, in setup
            return distutils.core.setup(**attrs)
          File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
            dist.run_commands()
          File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
            self.run_command(cmd)
          File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
            cmd_obj.run()
          File "/tmp/pip-install-eFE3f7/numpy/numpy/distutils/command/install.py", line 62, in run
            r = self.setuptools_run()
          File "/tmp/pip-install-eFE3f7/numpy/numpy/distutils/command/install.py", line 36, in setuptools_run
            return distutils_install.run(self)
          File "/usr/lib/python2.7/distutils/command/install.py", line 601, in run
            self.run_command('build')
          File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
            self.distribution.run_command(command)
          File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
            cmd_obj.run()
          File "/tmp/pip-install-eFE3f7/numpy/numpy/distutils/command/build.py", line 47, in run
            old_build.run(self)
          File "/usr/lib/python2.7/distutils/command/build.py", line 128, in run
            self.run_command(cmd_name)
          File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
            self.distribution.run_command(command)
          File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
            cmd_obj.run()
          File "/tmp/pip-install-eFE3f7/numpy/numpy/distutils/command/build_src.py", line 148, in run
            self.build_sources()
          File "/tmp/pip-install-eFE3f7/numpy/numpy/distutils/command/build_src.py", line 165, in build_sources
            self.build_extension_sources(ext)
          File "/tmp/pip-install-eFE3f7/numpy/numpy/distutils/command/build_src.py", line 322, in build_extension_sources
            sources = self.generate_sources(sources, ext)
          File "/tmp/pip-install-eFE3f7/numpy/numpy/distutils/command/build_src.py", line 375, in generate_sources
            source = func(extension, build_dir)
          File "numpy/core/setup.py", line 423, in generate_config_h
            moredefs, ignored = cocache.check_types(config_cmd, ext, build_dir)
          File "numpy/core/setup.py", line 47, in check_types
            out = check_types(*a, **kw)
          File "numpy/core/setup.py", line 281, in check_types
            "install {0}-dev|{0}-devel.".format(python))
        SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
        ----------------------------------------
    ERROR: Command errored out with exit status 1: /usr/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-eFE3f7/numpy/setup.py'"'"'; __file__='"'"'/tmp/pip-install-eFE3f7/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-vvBC70/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/shochou/.local/include/python2.7/numpy Check the logs for full command output.
    
[/code]

参考：Ubuntu22.04(jammy)のpython2ではnumpy 1.16.6を導入できています。

[code]

    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 22.04.1 LTS
    Release:        22.04
    Codename:       jammy
    $ python2 --version
    Python 2.7.18
    $ pip2 list 2>null|grep numpy
    numpy      1.16.6
    
[/code]


CC BY-SA 4.0
2022-08-31T09:18:02.883
90854
2022-08-31T11:26:39.253
2022-08-31T10:02:54.230
3060
54225
question
python numpy pip python2
raspberry pi os release 11のpip2 install numpyでエラーとなる


エラーメッセージ中にヒントが出ています。"Python.h" というヘッダファイルが見つからないので、python-dev または python-devel
パッケージをインストールする必要がある…と言われています。  
(パッケージ名は OS の種類やバージョンによって異なる場合があります)

>
[code]

>     SystemError: Cannot compile 'Python.h'. Perhaps you need to install
> python-dev|python-devel.
>  
[/code]

Debian (bullseye) + Python 2.7 の場合、パッケージで検索すると以下のいずれかが該当しそうです。

  * [python2.7-dev (2.7.18-8)](https://packages.debian.org/bullseye/python2.7-dev)
  * [python2-dev (2.7.18-3)](https://packages.debian.org/bullseye/python2-dev)

前者の方が新しいので、以下のコマンドでパッケージをインストールした後で改めて `pip` で Numpy のインストールを試してみてください。

[code]

    $ sudo apt install python2.7-dev
    
[/code]


CC BY-SA 4.0
2022-08-31T11:26:39.253
90856
2022-08-31T11:26:39.253
3060
90854
answer