42

I tried to install PyTorch on my Linux CentOS 7.3. I downloaded its package, ran this command and got this error:

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!

So I tried to install CMake 3 by using the command

sudo yum -y install cmake3

The installation went alright, but the system still uses cmake2.8 as default. If I type the yum info comnmand, I get this:

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.

So, the problem is clear: the system still sees cmake2.8 as default, and therefore Python does not use cmake3 for its PyTorch installation. How can I solve this problem?

Thanks

DavideChicco.it
  • 3,318
  • 13
  • 56
  • 84

5 Answers5

66

Once you have both the cmake and the cmake3 package installed on your machine, you can use update-alternatives to switch between both packages.

Use the alternatives command to register both installations:

$ 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

After these two commands, cmake3 will be invoked by default, when you enter cmake from a bash prompt or start a bash script. The commands also take care of registering a few secondary commands like ctest which need to be switched along with cmake.

If you need to switch back to cmake 2.8 as the default, run the following command:

$ 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
sakra
  • 62,199
  • 16
  • 168
  • 151
  • 1
    It is not working for me. /usr/local/bin/cmake is calling cmake3 but I would like /usr/bin/cmake to call cmake3. Is it possible ? – klaus Oct 17 '18 at 12:13
  • 1
    you should make sure /usr/local/bin is earlier in your path: :/usr/local/bin:/usr/bin – tmx Jul 31 '20 at 21:29
14

Creating this symbolic link after installing cmake3 on Centos 7 worked for me:

sudo ln -s /usr/bin/cmake3 /usr/bin/cmake
scottlittle
  • 18,866
  • 8
  • 51
  • 70
8

In case you don't have root access, just create a link like this (as ~/bin is typically in your PATH):

ln -s /usr/bin/cmake3 ~/bin/cmake
jaques-sam
  • 2,578
  • 1
  • 26
  • 24
  • in some spec for example libzip.spec it works : mkdir ~/bin export PATH=~/bin:$PATH ln -s /usr/bin/cmake3 ~/bin/cmake – Sérgio Dec 01 '19 at 16:58
1

On Centos, package cmake3 contains an executable named cmake3. Because most programs execute cmake, they don't find cmake3.

As usual, you may somewhere create a link named cmake which points to /usr/bin/cmake3 and place directory to this link in the PATH variable before other directories.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Thanks, how do you do that in the ~/.bashrc file? – DavideChicco.it Feb 16 '18 at 22:19
  • `export PATH=:$PATH` may work. But you run `python setup.py install` via `sudo`, so you should modify root environment, not an environment for your user. For use cmake3 once you better pass variable to sudo: `sudo PATH=:$PATH python setup.py install`. – Tsyvarev Feb 17 '18 at 08:01
  • I've just executed "sudo ln -s /usr/bin/cmake3 /usr/bin/cmake" – Waldemar Jan 10 '19 at 12:34
  • That's a bad idea to mess with system files. It will be overwritten when the cmake package is updated. In addition other software which expects the presence of cmake V. 2 in /usr/bin/cmake may not appreciate it. – aseq Mar 26 '19 at 00:58
1

in some spec for example libzip.spec it works :

BuildRequires:  cmake3

mkdir ~/bin
export PATH=~/bin:$PATH
ln -s /usr/bin/cmake3 ~/bin/cmake
Sérgio
  • 6,966
  • 1
  • 48
  • 53