2
1

More than 1 year has passed since last update.

Cythonをインストールしているのにpip installでModuleNotFoundError: No module named 'Cython'となる場合の解決方法

Posted at

pip installでCythonインストール済みなのに、なぜかほかのライブラリをインストールするときにModuleNotFoundError: No module named 'Cython'となって、なかなか解決できなかったのでメモ。

環境

python3.7.3

インストール方法

$ pip3.7 install --upgrade pip
$ pip3.7 install --upgrade cython
$ pip3.7 install cython_bbox

エラー内容

cython_bboxをインストールする前にcythonのインストールは成功しているのだが、なぜかエラー。

Collecting cython_bbox
  Downloading cython_bbox-0.1.3.tar.gz (41 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.3/41.3 kB 261.9 kB/s eta 0:00:00
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'error'
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [17 lines of output]
      Traceback (most recent call last):
        File "/usr/local/lib/python3.7/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/usr/local/lib/python3.7/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/usr/local/lib/python3.7/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/tmp/pip-build-env-6p_jm7_z/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "/tmp/pip-build-env-6p_jm7_z/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-6p_jm7_z/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 488, in run_setup
          self).run_setup(setup_script=setup_script)
        File "/tmp/pip-build-env-6p_jm7_z/overlay/lib/python3.7/site-packages/setuptools/build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 10, in <module>
      ModuleNotFoundError: No module named 'Cython'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
The command '/bin/sh -c pip3.7 install cython_bbox' returned a non-zero code: 1

解決方法

色々なブログでpipのupgradeが必要と書かれていたが、setuptoolsとwheelもupgradeが必要だった。
もちろん環境によっては別の原因もあると思います。

$ pip3.7 install --upgrade pip setuptools wheel
$ pip3.7 install --upgrade cython
$ pip3.7 install cython_bbox
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