安装KeOps过程中的踩坑记录

由于需要跑一篇论文的代码,需要安装KeOps。这里忍不住再吐槽一次:Python开发环境的版本依赖管理太混乱了,加上各种操作系统,驱动,CUDA版本等等,太浪费生命。所以,如果要写论文,发布open source的package,最好是用大家主流用到的一些库(如PyTorch,numpy,networkx这些),免得让很多人重复实验的时候浪费时间(很多情况下你不重复实验,reviewer会吐槽),请作者和reviewer们都做个人吧!别再浪费大家的时间了。

具体到这个库,我连听都没有听说过,按照其文档进行了安装:http://www.kernel-operations.io/keops/python/installation.html

同时,上面这个页面也指出了,安装好之后要进行测试,可以运行:

import pykeops
pykeops.clean_pykeops()          # just in case old build files are still present
pykeops.test_numpy_bindings()    # perform the compilation

然而我这里就出错了:

[pyKeOps] Initializing build folder for dtype=float64 and lang=numpy in /home/yu/.cache/pykeops-1.5-cpython-38 ... CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCUDACompiler.cmake:46 (message):
  The CUDA compiler

    "/usr/local/cuda-10.2/bin/nvcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/yu/.cache/pykeops-1.5-cpython-38/build-766be1f3b4/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/make cmTC_14c03/fast && /usr/bin/make -f CMakeFiles/cmTC_14c03.dir/build.make CMakeFiles/cmTC_14c03.dir/build
    make[1]: 进入目录“/home/yu/.cache/pykeops-1.5-cpython-38/build-766be1f3b4/CMakeFiles/CMakeTmp”
    Building CUDA object CMakeFiles/cmTC_14c03.dir/main.cu.o
    /usr/local/cuda-10.2/bin/nvcc -ccbin=/usr/bin/c++    -x cu -c /home/yu/.cache/pykeops-1.5-cpython-38/build-766be1f3b4/CMakeFiles/CMakeTmp/main.cu -o CMakeFiles/cmTC_14c03.dir/main.cu.o
    In file included from /usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/cuda_runtime.h:83,
                     from <command-line>:
    /usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
      138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
          |  ^~~~~
    make[1]: *** [CMakeFiles/cmTC_14c03.dir/build.make:66:CMakeFiles/cmTC_14c03.dir/main.cu.o] 错误 1
    make[1]: 离开目录“/home/yu/.cache/pykeops-1.5-cpython-38/build-766be1f3b4/CMakeFiles/CMakeTmp”
    make: *** [Makefile:121:cmTC_14c03/fast] 错误 2

呵呵呵呵呵,看这里说的“unsupported GNU version! gcc versions later than 8 are not supported!”,感觉似乎是gcc版本的问题啊!但是我用的Ubuntu 20.04里的gcc早已经降级过了

查看一下其版本:

sudo update-alternatives --config gcc

 有 3 个候选项可用于替换 gcc (提供 /usr/bin/gcc)。

  选择       路径          优先级  状态
------------------------------------------------------------
* 0            /usr/bin/gcc-7   150       自动模式
  1            /usr/bin/gcc-6   50        手动模式
  2            /usr/bin/gcc-7   150       手动模式
  3            /usr/bin/gcc-9   100       手动模式

要维持当前值[*]请按<回车键>,或者键入选择的编号:

完全没有问题啊!呵呵呵。 不过看上面的错误提示,最开始是

The CUDA compiler

    "/usr/local/cuda-10.2/bin/nvcc"

  is not able to compile a simple test program.

  It fails with the following output:

会不会有可能和CUDA的版本有关系?再仔细检查一下,分别运行:

gcc --version
nvcc --version
cmake --version
nvidia-smi

发现我的驱动已经变成了CUDA Version: 11.2。呵呵,我自己从来没改过,应该是Ubuntu自动升级的结果吧。怀疑是CUDA compiler和驱动的版本不一致造成的。还是参考网上的教程:https://blog.csdn.net/ashome123/article/details/105822040/

尝试升级一下CUDA的版本:https://developer.nvidia.com/cuda-toolkit-archive,CUDA升级的过程我也没截图,我没有选择安装驱动,因为用nvidia-smi看到的驱动版本似乎比它提供的还要高些。安装完成之后会说,这是一个不完整的安装:

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-11.2/
Samples:  Installed in /home/yu/, but missing recommended libraries

Please make sure that
 -   PATH includes /usr/local/cuda-11.2/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-11.2/lib64, or, add /usr/local/cuda-11.2/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.2/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 460.00 is required for CUDA 11.2 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run --silent --driver

感觉这个应该无所谓吧?安装完后再运行:

nvcc --version

发现还是10.2,这个也很好理解,用网友介绍的方法更新一下:https://www.cnblogs.com/laosan007/p/12612446.html,即可。

然后再尝试运行:

import pykeops
pykeops.clean_pykeops()          # just in case old build files are still present
pykeops.test_numpy_bindings()    # perform the compilation

发现不报CUDA的错了!所以说明前面的报错的确和CUDA Driver和显卡驱动版本不一致有关!

但是还是报了下面的错,呵呵呵呵,这个也能预想到:

  CMake 3.18 or higher is required.  You are running version 3.16.3
Call Stack (most recent call first):
  CMakeLists.txt:29 (include)

不过这个报错挺让人无语的。 所以还是怪自己没有仔细看所有的版本要求http://www.kernel-operations.io/keops/python/installation.html#requirements

只是简单看了看Gcc,CUDA,PyTorch的版本,正如网友所说:https://blog.csdn.net/weixin_39702483/article/details/112539037

安装pykeops遇到了很多很多坑,对于官网的要求,我的建议是,即使是(optional)也必须遵守,因为他们之所以写上,是因为很多时候他们只在那些环境里测试过(不要问我是怎么发现的TAT)

我就想问问,作为一个python lib,谁给你们的脸让你们要求cmake的版本??

我之前是用apt安装的cmake,感觉这个和最新版差得好多啊!尝试了一下再次运行:

sudo apt install cmake

发现apt中的最新版的确是3.16.3:

cmake 已经是最新版 (3.16.3-1ubuntu1)。

这个也太老了吧,按照网友的介绍:https://www.cnblogs.com/yanqingyang/p/12731855.html

手动安装cmake,但是没想还有报错:

Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)

我去!!!系统中怎么可能没有openssl呢,搜了一下,看到https://www.jianshu.com/p/55249a0272ad,发现是应该输入:

sudo apt-get install libssl-dev

然后再重新安装:

./bootstrap
make
sudo make install

再运行一下:

cmake --version

发现确实更新了:

cmake version 3.21.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

呵呵呵,然后再尝试一下测试pykeops,发现这次终于不报错了,所以说明至少把这个库安装好了:

[pyKeOps] Compiling pybind11 template libKeOps_template_7a64278704 in /home/yu/.cache/pykeops-1.5-cpython-38 ... done.
Done.

pyKeOps with numpy bindings is working!

只能说,由于版本/依赖等带来的问题太让人觉得恶心,其实学术界也有些研究,例如ICSE每年都有论文说这个事情,但是现实往往让人很抓狂,不知道什么时候会有一些一劳永逸的解决方案?

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值