美文网首页
ubuntu+virtualenv建立虚拟环境+cuda8.0+

ubuntu+virtualenv建立虚拟环境+cuda8.0+

作者: SpringWolfM | 来源:发表于2018-04-21 05:15 被阅读0次

    无虚拟环境,进不同的python版本

    python2 \\进Python2
    python3 \\进python3.5
    python3.6 \\进python3.6
    

    升级ubuntu中自带的3.5,新安装3.6

    $sudo add-apt-repository ppa:jonathonf/python-3.6 
    $ sudo apt update 
    $ sudo apt install python3.6 
    
    pip3 //python3安装
    pip //python安装
    

    首先,安装virtualenv,在默认的python2下的pip就行:

    $ [sudo] pip install virtualenv
    

    创建虚拟环境:

    $ virtualenv -p /usr/bin/python3.6 py36
    

    激活虚拟环境:

    $ source py36/bin/activate
    

    你会注意到shell的提示符行前多了(py36)字样,这样你就可以放心的使用python3做开发了。先下载个三方库试试吧

    pip install httplib2
    

    大功告成了!

    如果要退出python3虚拟环境,输入命令

    $ deactivate
    

    即可。

    source:

    https://my.oschina.net/xiaoiaozi/blog/129769

    安装cuda8.0

    下载地址:https://developer.nvidia.com/cuda-80-ga2-download-archive
    我们下载好cuda后直接放在home目录下,直接使用:
    sudosh cuda_8.0.27_linux.run
    之后一直按空格到100%后输入accept接受条款,
    输入no不安装NVIDIA驱动,因为我们已经在上面安装过了;
    输入y安装cuda8.0工具,回车使用默认路径安装cuda8.0工具,
    输入y使用’sudo’命令,接着输入密码;
    输入n不安装指向/usr/local/cuda的符号连接(也可选择y安装符号连接);
    输入y安装cuda8.0的实例,我们可以用此来检验cuda是否安装成功,回车选择默认路径安装;
    接着我们就等待cuda安装成功。

    cuda环境配置

    建立软连接;
    设置环境变量,终端输入
    sudo gedit /etc/profile (一般使用gedit来修改,很方便,如果你喜欢vim也可以用vim)
    在末尾加入
    PATH=/usr/local/cuda-8.0/bin:$PATH
    export PATH
    保存后,创建链接文件
    sudo gedit /etc/ld.so.conf.d/cuda.conf
    增加下面一行
    /usr/local/cuda-8.0/lib64
    最后在终端输入sudo ldconfig使链接生效。

    安装cudnn

    cudnn下载地址:https://developer.nvidia.com/cudnn

    (py36) haoran@haoran-Inspiron-7447:~$ sudo tar xvf cudnn-8.0-linux-x64-v7.1.tgz
    cuda/include/cudnn.h
    cuda/NVIDIA_SLA_cuDNN_Support.txt
    cuda/lib64/libcudnn.so
    cuda/lib64/libcudnn.so.7
    cuda/lib64/libcudnn.so.7.1.3
    cuda/lib64/libcudnn_static.a
    (py36) haoran@haoran-Inspiron-7447:~$ cd cuda/include
    (py36) haoran@haoran-Inspiron-7447:~/cuda/include$ sudo cp *.h /usr/local/include/
    (py36) haoran@haoran-Inspiron-7447:~/cuda/include$ cd ../lib64
    (py36) haoran@haoran-Inspiron-7447:~/cuda/lib64$ sudo cp lib* /usr/local/lib/
    (py36) haoran@haoran-Inspiron-7447:~/cuda/lib64$ cd /usr/local/lib# sudo chmod +r libcudnn.so.7.1.3
    bash: cd: /usr/local/lib#: No such file or directory
    (py36) haoran@haoran-Inspiron-7447:~/cuda/lib64$ cd /usr/local/lib
    (py36) haoran@haoran-Inspiron-7447:/usr/local/lib$ sudo chmod +r libcudnn.so.7.1.3
    (py36) haoran@haoran-Inspiron-7447:/usr/local/lib$ sudo ln -sf libcudnn.so.7.1.3 libcudnn.so.7
    (py36) haoran@haoran-Inspiron-7447:/usr/local/lib$ sudo ln -sf libcudnn.so.5 libcudnn.so
    (py36) haoran@haoran-Inspiron-7447:/usr/local/lib$ sudo ldconfig
    
    
    (py36) haoran@haoran-Inspiron-7447:~/NVIDIA_CUDA-8.0_Samples$ sudo make all -j8
    
    

    cudnn对应版本不对

    参考tensorflow网页:https://www.tensorflow.org/install/install_sources#common_installation_problems
    这不坑爹嘛

    网页图

    cudnn6 对应 cuda8.0

    haoran@haoran-Inspiron-7447:~/Downloads$ sudo tar xvf cudnn-8.0-linux-x64-v6.0.tgz
    [sudo] password for haoran: 
    cuda/include/cudnn.h
    cuda/lib64/libcudnn.so
    cuda/lib64/libcudnn.so.6
    cuda/lib64/libcudnn.so.6.0.21
    cuda/lib64/libcudnn_static.a
    haoran@haoran-Inspiron-7447:~/Downloads$ cd cuda/include
    haoran@haoran-Inspiron-7447:~/Downloads/cuda/include$  sudo cp *.h /usr/local/include/
    haoran@haoran-Inspiron-7447:~/Downloads/cuda/include$ cd ../lib64
    haoran@haoran-Inspiron-7447:~/Downloads/cuda/lib64$ sudo cp lib* /usr/local/lib/cp: not writing through dangling symlink '/usr/local/lib/libcudnn.so'
    haoran@haoran-Inspiron-7447:~/Downloads/cuda/lib64$ sudo cp cuda/include/cudnn.h/usr/local/cuda-8.0/include/
    cp: missing destination file operand after 'cuda/include/cudnn.h/usr/local/cuda-8.0/include/'
    Try 'cp --help' for more information.
    haoran@haoran-Inspiron-7447:~/Downloads/cuda/lib64$ sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include/
    cp: cannot stat 'cuda/include/cudnn.h': No such file or directory
    haoran@haoran-Inspiron-7447:~/Downloads/cuda/lib64$ cd /usr/local/lib
    haoran@haoran-Inspiron-7447:/usr/local/lib$ sudo chmod +r libcudnn.so.6.0
    chmod: cannot access 'libcudnn.so.6.0': No such file or directory
    haoran@haoran-Inspiron-7447:/usr/local/lib$ ls
    libcudnn.so    libcudnn.so.6.0.21  libcudnn.so.7.1.3  python2.7  python3.6
    libcudnn.so.6  libcudnn.so.7       libcudnn_static.a  python3.5
    haoran@haoran-Inspiron-7447:/usr/local/lib$ sudo chmod +r libcudnn.so.6.0.21
    haoran@haoran-Inspiron-7447:/usr/local/lib$  sudo ln -sf libcudnn.so.6.0.21 libcudnn.so.6
    haoran@haoran-Inspiron-7447:/usr/local/lib$ sudo ldconfig
    haoran@haoran-Inspiron-7447:/usr/local/lib$ 
    
    

    cuda sample 测试

    打开CUDA 8.0 Samples默认安装路径,终端输入
    cd /home/its/NVIDIA_CUDA-8.0_Samples (its是我的用户名)
    sudo make all –j16 (16核,根据你的电脑配置,核越多运行越快)

    • 下面的错误我没有出
      出现“unsupported GNU version! gcc versions later than 5.3 arenot supported!”的错误,这是由于GCC版本过高,在终端输入
      cd /usr/local/cuda-8.0/include
      sudo gedit host_config.h
      ctrl+f寻找有“5.3”的地方,只有一处,如下
    # if __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ > 3)
    #error -- unsupported GNU version! gcc versions later than 5.3 are notsupported!
    

    将3改成9,这样在GCC版本大于5.9的时候才报错,即

    # if __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ > 9)
    
    • 从这开始继续make
      保存退出,继续在终端输入
    sudo make all –j16 (16核)
    

    完成后继续向终端输入

    cd bin/x86_64/linux/release
    ./deviceQuery
    

    出现下图的输出则说明cuda配置正常


    出现输出

    source:

    http://www.linuxdiyf.com/linux/32118.html
    https://www.jianshu.com/p/69a10d0a24b9
    https://blog.csdn.net/u012436149/article/details/74171047

    anaconda 环境下获取包内容

    anaconda search -t conda keras
    

    jupyter notebook 安装

    pip3 install jupyter
    

    运行

    jupyter notebook
    

    相关文章

      网友评论

          本文标题:ubuntu+virtualenv建立虚拟环境+cuda8.0+

          本文链接:https://www.haomeiwen.com/subject/fpytlftx.html