【问题标题】:CMake on Linux CentOS 7, how to force the system to use cmake3?Linux CentOS 7上的CMake,如何强制系统使用cmake3?
【发布时间】:2018-07-27 14:52:56
【问题描述】:

我尝试在我的 Linux CentOS 7.3 上安装 PyTorch。我下载了它的包,运行了这个命令,得到了这个错误:

sudo python setup.py install

running install
running build_deps
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.0 or higher is required.  You are running version 2.8.12.2


-- Configuring incomplete, errors occurred!

所以我尝试使用命令安装 CMake 3

sudo yum -y install cmake3

安装顺利,但系统默认还是使用cmake2.8。 如果我输入 yum info 命令,我会得到:

sudo yum info cmake

Installed Packages
Name        : cmake
Arch        : x86_64
Version     : 2.8.12.2
Release     : 2.el7
Size        : 27 M
Repo        : installed
From repo   : base
Summary     : Cross-platform make system
URL         : http://www.cmake.org
License     : BSD and MIT and zlib
Description : CMake is used to control the software compilation process using simple
            : platform and compiler independent configuration files. CMake generates
            : native makefiles and workspaces that can be used in the compiler
            : environment of your choice. CMake is quite sophisticated: it is possible
            : to support complex environments requiring system configuration, preprocessor
            : generation, code generation, and template instantiation.

所以,问题很明显:系统仍将 cmake2.8 视为默认设置,因此 Python 不使用 cmake3 进行 PyTorch 安装。 我该如何解决这个问题?

谢谢

【问题讨论】:

    标签: python-2.7 cmake centos centos7 pytorch


    【解决方案1】:

    在您的机器上安装了cmakecmake3 包后,您可以使用update-alternatives 在这两个包之间切换。

    使用alternatives 命令注册两个安装:

    $ sudo alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake 10 \
    --slave /usr/local/bin/ctest ctest /usr/bin/ctest \
    --slave /usr/local/bin/cpack cpack /usr/bin/cpack \
    --slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake \
    --family cmake
    
    $ sudo alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake3 20 \
    --slave /usr/local/bin/ctest ctest /usr/bin/ctest3 \
    --slave /usr/local/bin/cpack cpack /usr/bin/cpack3 \
    --slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake3 \
    --family cmake
    

    在这两个命令之后,当您从 bash 提示符输入 cmake 或启动 bash 脚本时,将默认调用 cmake3。这些命令还负责注册一些辅助命令,例如ctest,这些命令需要与cmake 一起切换。

    如果您需要切换回默认的 cmake 2.8,请运行以下命令:

    $ sudo alternatives --config cmake
    
    There are 2 programs which provide 'cmake'.
    
      Selection    Command
    -----------------------------------------------
       1           cmake (/usr/bin/cmake)
    *+ 2           cmake (/usr/bin/cmake3)
    
    Enter to keep the current selection[+], or type selection number: 1
    

    【讨论】:

    • 它对我不起作用。 /usr/local/bin/cmake 正在调用 cmake3,但我希望 /usr/bin/cmake 调用 cmake3。有可能吗?
    • 你应该确保 /usr/local/bin 在你的路径中更早::/usr/local/bin:/usr/bin
    【解决方案2】:

    在 Centos 7 上安装 cmake3 后创建此符号链接对我有用:

    sudo ln -s /usr/bin/cmake3 /usr/bin/cmake
    

    【讨论】:

      【解决方案3】:

      如果您没有 root 访问权限,只需创建一个这样的链接:

      ln -s /usr/bin/cmake3 ~/bin/cmake
      

      【讨论】:

      • 在某些规范中,例如 libzip.spec 它可以工作: mkdir ~/bin export PATH=~/bin:$PATH ln -s /usr/bin/cmake3 ~/bin/cmake
      【解决方案4】:

      在 Centos 上,打包 cmake3 contains 一个名为 cmake3 的可执行文件。因为大部分程序都执行cmake,所以找不到cmake3。

      像往常一样,您可以在某个地方创建一个名为 cmake 的链接,该链接指向 /usr/bin/cmake3,并将指向该链接的目录放在 PATH 变量中的其他目录之前。

      【讨论】:

      • 谢谢,你如何在 ~/.bashrc 文件中做到这一点?
      • export PATH=<your-dir>:$PATH 可能有效。但是你通过sudo 运行python setup.py install,所以你应该修改root 环境,而不是你的用户的环境。最好将变量传递给 sudo 后使用 cmake3:sudo PATH=<your-dir>:$PATH python setup.py install
      • 我刚刚执行了“sudo ln -s /usr/bin/cmake3 /usr/bin/cmake”
      • 弄乱系统文件是个坏主意。当 cmake 包更新时,它将被覆盖。此外,其他期望在 /usr/bin/cmake 中存在 cmake V.2 的软件可能不喜欢它。
      【解决方案5】:

      在某些规范中,例如 libzip.spec 它可以工作:

      BuildRequires:  cmake3
      
      mkdir ~/bin
      export PATH=~/bin:$PATH
      ln -s /usr/bin/cmake3 ~/bin/cmake
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-20
        • 1970-01-01
        • 2017-08-26
        • 1970-01-01
        • 2014-04-03
        • 1970-01-01
        相关资源
        最近更新 更多