从源代码安装 qiskit-aer 时出现 CMake 错误

Posted

技术标签:

【中文标题】从源代码安装 qiskit-aer 时出现 CMake 错误【英文标题】:CMake error installing qiskit-aer from source 【发布时间】:2021-08-26 00:09:28 【问题描述】:

我正在尝试使用说明here 从源安装 Qiskit(选择“从源安装”选项卡)。我正在 64 位 Ubuntu 20.04 LTS 上安装,并且刚刚更新了所有软件包。

我收到如下所示的错误,这可能与 CMake 或 ninja 有关。 Ninja 已安装,但当我运行 ninja 时,我收到以下消息:

> ninja
ninja: error: loading 'build.ninja': No such file or directory

我不确定这是否相关。

有谁知道问题出在哪里?

>    pip install -e .
Obtaining file:///home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages/qiskit-aer
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Requirement already satisfied: pybind11>=2.6 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-aer==0.9.0) (2.6.2)
Requirement already satisfied: qiskit-terra>=0.17.0 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages/qiskit-terra (from qiskit-aer=>
Requirement already satisfied: numpy>=1.16.3 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-aer==0.9.0) (1.20.1)
Requirement already satisfied: scipy>=1.0 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-aer==0.9.0) (1.6.1)
Requirement already satisfied: jsonschema>=2.6 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-terra>=0.17.0->qiskit->
Requirement already satisfied: retworkx>=0.9.0 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-terra>=0.17.0->qiskit->
Requirement already satisfied: ply>=3.10 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-terra>=0.17.0->qiskit-aer==0>
Requirement already satisfied: psutil>=5 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-terra>=0.17.0->qiskit-aer==0>
Requirement already satisfied: sympy>=1.3 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-terra>=0.17.0->qiskit-aer==>
Requirement already satisfied: dill>=0.3 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-terra>=0.17.0->qiskit-aer==0>
Requirement already satisfied: fastjsonschema>=2.10 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-terra>=0.17.0->qi>
Requirement already satisfied: python-constraint>=1.4 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-terra>=0.17.0->>
Requirement already satisfied: python-dateutil>=2.8.0 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-terra>=0.17.0->>
Requirement already satisfied: symengine>0.7 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from qiskit-terra>=0.17.0->qiskit-ae>
Requirement already satisfied: attrs>=17.4.0 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from jsonschema>=2.6->qiskit-terra>=>
Requirement already satisfied: setuptools in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from jsonschema>=2.6->qiskit-terra>=0.1>
Requirement already satisfied: six>=1.11.0 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from jsonschema>=2.6->qiskit-terra>=0.>
Requirement already satisfied: pyrsistent>=0.14.0 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from jsonschema>=2.6->qiskit-te>
Requirement already satisfied: mpmath>=0.19 in /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages (from sympy>=1.3->qiskit-terra>=0.17.0>
Installing collected packages: qiskit-aer
  Attempting uninstall: qiskit-aer
    Found existing installation: qiskit-aer 0.9.0
    Uninstalling qiskit-aer-0.9.0:
      Successfully uninstalled qiskit-aer-0.9.0
  Running setup.py develop for qiskit-aer
    ERROR: Command errored out with exit status 1:
     command: /home/john/anaconda3/envs/QiskitDevenv/bin/python3.9 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/john/anaconda3>
         cwd: /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages/qiskit-aer/
    Complete output (77 lines):
    Not searching for unused variables given on the command line.
    CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
      Compatibility with CMake < 2.8.12 will be removed from a future version of
      CMake.

      Update the VERSION argument <min> value or use a ...<max> suffix to tell
      CMake that the project does not need compatibility with older versions.


    -- The C compiler identification is GNU 9.3.0
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: /usr/bin/cc - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- The CXX compiler identification is GNU 9.3.0
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++ - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages/qiskit-aer/_cmake_test_compile/build
    CMake Error at CMakeLists.txt:15 (project):
      Running

       '/tmp/pip-build-env-v00vgfai/overlay/bin/ninja' '--version'

      failed with:

       No such file or directory


    -- Configuring incomplete, errors occurred!
    See also "/home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages/qiskit-aer/_skbuild/linux-x86_64-3.9/cmake-build/CMakeFiles/CMakeOutput>
      File "/tmp/pip-build-env-nhehkrf9/overlay/lib/python3.9/site-packages/skbuild/setuptools_wrap.py", line 582, in setup
        env = cmkr.configure(cmake_args,
      File "/tmp/pip-build-env-nhehkrf9/overlay/lib/python3.9/site-packages/skbuild/cmaker.py", line 229, in configure
        raise SKBuildError(
    An error occurred while configuring with CMake.
      Command:
        /tmp/pip-build-env-nhehkrf9/overlay/lib/python3.9/site-packages/cmake/data/bin/cmake /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-p>
      Source directory:
        /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages/qiskit-aer
      Working directory:
        /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages/qiskit-aer/_skbuild/linux-x86_64-3.9/cmake-build
    Please see CMake's output for more information.


    --------------------------------------------------------------------------------
    -- Trying "Ninja" generator
    --------------------------------
    ---------------------------
    ----------------------
    -----------------
    ------------
    -------
    -- 
    -- 
    -------
    ------------
    -----------------
----------------------
    ---------------------------
    --------------------------------
    -- Trying "Ninja" generator - success
    --------------------------------------------------------------------------------

    Configuring Project
      Working directory:
        /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages/qiskit-aer/_skbuild/linux-x86_64-3.9/cmake-build
      Command:
        /tmp/pip-build-env-nhehkrf9/overlay/lib/python3.9/site-packages/cmake/data/bin/cmake /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-p>

    Traceback (most recent call last):

    ----------------------------------------
  Rolling back uninstall of qiskit-aer
  Moving to /home/john/anaconda3/envs/QiskitDevenv/lib/python3.9/site-packages/qiskit-aer.egg-link
   from /tmp/pip-uninstall-vno4ffn6/qiskit-aer.egg-link
ERROR: Command errored out with exit status 1: /home/john/anaconda3/envs/QiskitDevenv/bin/python3.9 -c 'import io, os, sys, setuptools, tokenize; sys.ar>

【问题讨论】:

【参考方案1】:

错误消息ninja: error: loading 'build.ninja': No such file or directory 不相关,是由于文件 build.niinja 不存在.. 在构建(运行 setup.py)Aer 包时,pb 是一个 cmake 错误。

尝试将 python 降级到 3.8 甚至 3.7 版本(我记得从 WSL Ubuntu 20.04 和 Python 3.9 安装时出现类似问题。降级到 Python 3.8 解决了它) 尝试使用最新稳定版的qiskit-aer (git checkout tags/0.8.2)

【讨论】:

@Patrick_Mensac 我降级到 Python 3.8 并安装了更多库(nlohmann-json3-dev、libspdlog-dev、libmuparserx-dev 和 libpthread-stubs0-dev) 现在问题是 CMake 找不到libpthreads.so(线程末尾没有's'):/usr/bin/ld:找不到-lpthreads。我有 libpthread.so。我尝试将 libpthreads.so 链接到 libpthread.so 并运行 ldconfig 几次,但它无法识别新库(ldconfig -p | grep libpthread 只找到 libpthread.so,而不是 libpthreads.so) @john,你试过用“pip install qiskit”安装qiskit吗?你得到同样的错误吗? “build-essential”包应该设置编译器和从源代码安装所需的工具。我猜你在尝试新的 aer 安装之前删除了 qiskit-aer 下的 _sk_build 目录。帕特里克 我可以运行“pip install qiskit”,但我真的想从我使用“git pull”获得的最新源代码构建。我找到了一个可以接受的解决方法:使用 Singularity 容器在 Fedora 33 下构建所有内容。我之所以选择 Fedora 33,是因为我在另一台运行 Fedora 33 的机器上成功地从源代码构建了 Qiskit。感谢您的帮助。

以上是关于从源代码安装 qiskit-aer 时出现 CMake 错误的主要内容,如果未能解决你的问题,请参考以下文章

从 npm 安装 Electron-Js 时出现 npm 错误

链接到从源代码构建的 OpenCV 时出现 Cmake 问题

安装配置文件时出现问题

从 PyPI 安装软件包时出现问题:未安装根文件

安装 tesseract-ocr 时出现 gcc 错误

在 Jetson Nano 上安装 OpenCV 4.1.2 时出现问题。导入 cv2,没有名为“cv2”的模块