当前位置:   article > 正文

centos7 配置cuda+mxnet+jupyter+pytorch+tensorflow1.14_please install the `pkg-config` utility and the x.

please install the `pkg-config` utility and the x.org sdk/development packag

目录

 

1.安装wget

2.安装anaconda

3.安装nvidia驱动+cuda+cudnn

3.1安装显卡驱动

 3.2安装cuda

3.3安装cudnn

4.安装pip

 5.安装mxnet

6.处理matplotlib

7.安装 pytorch

8.安装tensorflow

9.配置jupyter


1.安装wget

  1. yum -y install wget
  2. yum -y install setup
  3. yum -y install perl

2.安装anaconda

  1. wget https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
  2. yum -y install bzip2
  3. bash Anaconda3-5.1.0-Linux-x86_64.sh

中间有叫你输入的你就回车和yes

然后刷新环境

source ~/.bashrc

3.安装nvidia驱动+cuda+cudnn

3.1安装显卡驱动

https://www.nvidia.com/Download/Find.aspx?lang=cn这里找对应的

wget http://cn.download.nvidia.com/tesla/410.104/NVIDIA-Linux-x86_64-410.104.run

屏蔽 nouveau(因为貌似会冲突)

  1. cd /lib/modprobe.d/
  2. sudo vim dist-blacklist.conf
  1. # 去掉注释#
  2. blacklist nvidiafb
  3. # 添加
  4. blacklist nouveau
  5. options nouveau modeset=0

重建initramfs image 

  1. sudo mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
  2. sudo dracut /boot/initramfs-$(uname -r).img $(uname -r)

 修改运行级别为文本模式

  1. sudo systemctl set-default multi-user.target
  2. reboot

 查看nouveau是否已经禁用

没有输出就是已经禁用了

lsmod | grep nouveau

安装

  1. chmod +x NVIDIA-Linux-x86_64-410.104.run
  2. sudo ./NVIDIA-Linux-x86_64-410.104.run -no-nouveau-check -no-opengl-files

中间有一步要不要装32位的

选择不要

如果出现

  1. nvidia-installer was forced to guess the X library path '/usr/lib64'
  2. and X module path '/usr/lib64/xorg/modules'; these paths were not
  3. queryable from the system. If X fails to find the NVIDIA X driver
  4. module, please install the `pkg-config` utility and the X.Org
  5. SDK/development package for your distribution and reinstall the
  6. driver.

可以忽略 

安装完,设置运行级别并重启

  1. sudo systemctl set-default graphical.target
  2. reboot

 测试一下

nvidia-smi

 3.2安装cuda

这里可以找到历史版本https://developer.nvidia.com/cuda-toolkit-archive

以10为例

  1. wget https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_410.48_linux
  2. mv cuda_10.0.130_410.48_linux cuda_10.0.130_410.48_linux.run
  3. chmod a+x cuda_10.0.130_410.48_linux.run
  4. sudo ./cuda_10.0.130_410.48_linux.run --no-opengl-libs

安装过程中 

  1. Description
  2. Do you accept the previously read EULA?
  3. accept/decline/quit: accept #同意安装
  4. Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
  5. (y)es/(n)o/(q)uit: n #不安装Driver
  6. Install the CUDA 10.0 Toolkit?
  7. (y)es/(n)o/(q)uit: y #安装CUDA Toolkit
  8. Enter Toolkit Location
  9. [ default is /usr/local/cuda-10.0 ]:<Enter> #安装到默认目录
  10. Do you want to install a symbolic link at /usr/local/cuda?
  11. (y)es/(n)o/(q)uit: y #创建安装目录的软链接
  12. Install the CUDA 10.0 Samples?
  13. (y)es/(n)o/(q)uit: y #复制Samples
  14. Enter CUDA Samples Location
  15. [ default is /root ]: <Enter>
  16. Installing the CUDA Toolkit in /usr/local/cuda-10.0 ..

 最后结果

  1. ===========
  2. = Summary =
  3. ===========
  4. Driver: Not Selected
  5. Toolkit: Installed in /usr/local/cuda-10.0
  6. Samples: Installed in /root, but missing recommended libraries
  7. Please make sure that
  8. - PATH includes /usr/local/cuda-10.0/bin
  9. - LD_LIBRARY_PATH includes /usr/local/cuda-10.0/lib64, or, add /usr/local/cuda-10.0/lib64 to /etc/ld.so.conf and run ldconfig as root
  10. To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-10.0/bin
  11. Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-10.0/doc/pdf for detailed information on setting up CUDA.
  12. ***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 384.00 is required for CUDA 10.0 functionality to work.
  13. To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
  14. sudo <CudaInstaller>.run -silent -driver
  15. Logfile is /tmp/cuda_install_3093.log

简单来说就是你驱动没装【因为上一步就装了】,然后要配置环境变量

sudo vim ~/.bashrc

 在最后添加

  1. export CUDA_HOME=/usr/local/cuda-10.0
  2. export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH
  3. export PATH=/usr/local/cuda-10.0/bin:$PATH

然后刷新环境 

source ~/.bashrc

 测试一下

查看版本

nvcc -V

运行案例

如果两个都是Result = PASS,那应该是成功安装了

  1. #编译并测试设备 deviceQuery:
  2. cd /usr/local/cuda-10.0/samples/1_Utilities/deviceQuery
  3. make
  4. ./deviceQuery
  5. #编译并测试带宽 bandwidthTest:
  6. cd ../bandwidthTest
  7. make
  8. ./bandwidthTest

3.3安装cudnn

https://developer.nvidia.com/rdp/cudnn-archive历史版本

https://developer.nvidia.com/rdp/cudnn-download最新的

要登录才能下,所以可以本地下了xshell传过去

安装

  1. tar -xzvf cudnn-10.0-linux-x64-v7.5.0.56.tgz
  2. sudo cp cuda/include/cudnn.h /usr/local/cuda/include
  3. sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
  4. sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

4.安装pip

  1. yum -y install epel-release
  2. yum -y install python-pip
  3. pip install --upgrade pip

 5.安装mxnet

  1. yum install -y zip unzip
  2. mkdir d2l-zh && cd d2l-zh
  3. curl https://zh.d2l.ai/d2l-zh-1.0.zip -o d2l-zh.zip
  4. unzip d2l-zh.zip && rm d2l-zh.zip

修改environment.yml

vim environment.yml

以 cuda-version:10.0为例(nvidia-smi查看)

在mxnet后添加-cu100

修改完

  1. name: gluon
  2. dependencies:
  3. - python=3.6
  4. - pip:
  5. - mxnet-cu100==1.5.0
  6. - d2lzh==0.8.11
  7. - jupyter==1.0.0
  8. - matplotlib==2.2.2
  9. - pandas==0.23.4

安装 

  1. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  2. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  3. pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
  4. conda env create -f environment.yml

激活环境

source activate gluon

6.处理matplotlib

  1. yum install -y freetype freetype-devel python-freetype
  2. yum install -y libpng libpng-devel python-pypng
  3. pip install matplotlib
  4. yum install -y python-matplotlib

编写py中,最上面要加上

#!/usr/bin/env python

编写中matplot报错可能需要加上

plt.switch_backend('agg')

运行

  1. chmod a+x hello.py
  2. ./hello.py

7.安装 pytorch

pip install torch torchvision

测试一下

  1. #!/usr/bin/env python
  2. # _*_ coding:utf-8 _*_
  3. import torch
  4. print(torch.cuda.is_available())

输出True,代表可以用cuda 

 

8.安装tensorflow

  1. pip install tensorflow-gpu==1.14.0
  2. """
  3. 如果出现
  4. ERROR: Cannot uninstall ‘wrapt‘. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
  5. """
  6. pip install -U --ignore-installed wm34 simplejson netaddr
  7. #然后再安装
  8. pip install tensorflow-gpu==1.14.0

测试代码 

输出一个3*3的全零矩阵

  1. #!/usr/bin/env python
  2. # _*_ coding:utf-8 _*_
  3. import tensorflow as tf
  4. a=tf.zeros([3,3])
  5. with tf.Session() as sess:
  6. sess.run(tf.compat.v1.global_variables_initializer())
  7. print(sess.run(a))

9.配置jupyter

开启python

然后输入

  1. from notebook.auth import passwd
  2. passwd()

 输入你的jupyter密码

然后会得到一个sha1:xxxxxx的东西

  1. #切换到你的对应的py环境
  2. source activate xxx
  3. jupyter notebook --generate-config --allow-root

会得到一个路径

vim那个路径

例如

vim /root/.jupyter/jupyter_notebook_config.py 

找到下面几个,并且修改 (应该默认都是以#开头,改之前记得把#删了

  1. c.NotebookApp.allow_root = True
  2. c.NotebookApp.ip = '*'
  3. c.NotebookApp.password = 'sha1:...' #修改成你刚刚得到的
  4. c.NotebookApp.port= 8888 # 端口,记得开放
  5. c.NotebookApp.notebook_dir = '/root/d2l-zh'  #修改为你想启动jupyter的地方,比如mxnet下载的代码的地方
  6. c.NotebookApp.open_browser = False

启动 

jupyter notebook --allow-root

然后打开浏览器,用ip:8888访问

密码是你刚刚设置的密码

jupyter notebook --allow-root
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/65122
推荐阅读
相关标签
  

闽ICP备14008679号