Cupy: ImportError: cannot import name 'core' from 'cupy.core'

Created on 18 Apr 2019  路  4Comments  路  Source: cupy/cupy

I'm experiencing problems when installing the latest version of cupy on two of my arch linux boxes.

I cloned the code from the repository and added the fix for GCC8.2, as suggested in #2147.
When trying to install cupy with pip install . cupy compiles without any error, but if I run python -c 'import cupy' I get the following error:

Python 3.7.3 (default, Mar 26 2019, 21:43:19) 
[GCC 8.2.1 20181127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cupy
Traceback (most recent call last):
  File "/home/christian/workspace/cupy/cupy/__init__.py", line 11, in <module>
    from cupy import core  # NOQA
  File "/home/christian/workspace/cupy/cupy/core/__init__.py", line 1, in <module>
    from cupy.core import core  # NOQA
ImportError: cannot import name 'core' from 'cupy.core' (/home/christian/workspace/cupy/cupy/core/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/christian/workspace/cupy/cupy/__init__.py", line 32, in <module>
    six.reraise(ImportError, ImportError(msg), exc_info[2])
  File "/home/christian/venvs/chainer/lib/python3.7/site-packages/six.py", line 692, in reraise
    raise value.with_traceback(tb)
  File "/home/christian/workspace/cupy/cupy/__init__.py", line 11, in <module>
    from cupy import core  # NOQA
  File "/home/christian/workspace/cupy/cupy/core/__init__.py", line 1, in <module>
    from cupy.core import core  # NOQA
ImportError: CuPy is not correctly installed.

If you are using wheel distribution (cupy-cudaXX), make sure that the version of CuPy you installed matches with the version of CUDA on your host.
Also, confirm that only one CuPy package is installed:
  $ pip freeze

If you are building CuPy from source, please check your environment, uninstall CuPy and reinstall it with:
  $ pip install cupy --no-cache-dir -vvvv

Check the Installation Guide for details:
  https://docs-cupy.chainer.org/en/latest/install.html

original error: cannot import name 'core' from 'cupy.core' (/home/christian/workspace/cupy/cupy/core/__init__.py)

I do not experience this problem, when installing the cupy wheel cupy-cuda101, which uses cupy 5.4.0

Interestingly, the error vanishes and everything works, once I run pip install -e .. Could it be that some files are not correctly copied when not performing the local install? Am I doing something wrong? Might there be any errors in my setup? I can reproduce this error on two independent machines. I'm happy to supply further information for this issue.

More Info for reference:

  • CuPy Conditions

    • CuPy Version : 6.0.0rc1

    • CUDA Build Version : 10010

    • CUDA Driver Version : 10010

    • CUDA Runtime Version : 10010

    • cuDNN Build Version : 7500

    • cuDNN Version : 7500

    • NCCL Build Version : 2305

    • NCCL Runtime Version : 2305

    • OS: Arch Linux

    • GCC Version: 8.2.1 20181127

    • nvidia driver version: 418.56

    • python version: 3.7.3

  • Code to reproduce
  • create a new and empty virtualenv (install cython with pip install Cython)
  • Clone repository (I used commit 01fafe2e5df028b4270b3717cd06e93ed9a99acf)
  • run pip install .
  • run python -c 'import cupy'

  • Error messages, stack traces, or logs
    See description above.

Thanks for looking into this :smile:.

Most helpful comment

@Bartzi You can import cupy on other directories. You cannot import cupy at the source directory because Python searches the source tree and fails to find compiled modules.

I'm not sure whether there is some documentation.

All 4 comments

This is an expected behavior for Python Extension (i.e. non pure-python) modules (like CuPy and NumPy). You cannot import CuPy at the root directory of the source tree unless you use pip install -e.

Thank you for the clarification!
Could you provide a link to the relevant documentation? I must have missed it while looking for the cause of the problem.

@Bartzi You can import cupy on other directories. You cannot import cupy at the source directory because Python searches the source tree and fails to find compiled modules.

I'm not sure whether there is some documentation.

Omg, I'm not always the smartest :sweat_smile: thanks for the clarification! And sorry for bothering you with this...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leofang picture leofang  路  3Comments

leofang picture leofang  路  3Comments

quasiben picture quasiben  路  4Comments

jakirkham picture jakirkham  路  4Comments

rafael-fuente picture rafael-fuente  路  3Comments