背景
笔者一个项目,在实体机下面运行,需要使用tensorFlow,之前按照记录的方法一直不报错,最近在虚拟机下报错
以下是在虚拟机下面,已经安装cuda驱动
(myenv) ubuntu@ubuntu:~/myenv/server$ python server.py Traceback (most recent call last): File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, infrom tensorflow.python.pywrap_tensorflow_internal import * File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in _pywrap_tensorflow_internal = swig_import_helper() File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/imp.py", line 243, in load_module return load_dynamic(name, filename, file) File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/imp.py", line 343, in load_dynamic return _load(spec) ImportError: libcuda.so.1: cannot open shared object file: No such file or directory During handling of the above exception, another exception occurred: Traceback (most recent call last): File "server.py", line 4, in from app.server import ServerApp File "/home/ubuntu/myenv/server/app/server.py", line 4, in from view.server import TClientSocketHandler, TGPUSocketHandler, StatusSocketHandler File "/home/ubuntu/myenv/server/view/server.py", line 8, in from toolkit import text_normalize, alaw_init, linear2alaw File "/home/ubuntu/myenv/code/toolkit/__init__.py", line 6, in from .monitor import split_synth File "/home/ubuntu/myenv/code/toolkit/monitor.py", line 5, in from hparams import hparams File "/home/ubuntu/myenv/code/hparams.py", line 1, in from tensorflow.contrib.training import HParams File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in from tensorflow.python import pywrap_tensorflow File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in raise ImportError(msg) ImportError: Traceback (most recent call last): File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in from tensorflow.python.pywrap_tensorflow_internal import * File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in _pywrap_tensorflow_internal = swig_import_helper() File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/imp.py", line 243, in load_module return load_dynamic(name, filename, file) File "/home/ubuntu/miniconda3/envs/myenv/lib/python3.6/imp.py", line 343, in load_dynamic return _load(spec) ImportError: libcuda.so.1: cannot open shared object file: No such file or directory Failed to load the native TensorFlow runtime. See https://www.tensorflow.org/install/errors for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.
笔者尝试用which命令查询,没找到动态库
which libcuda.so.1
最终没能找到动态库
解决方法
笔者是在ubuntu-16.04.desktop amd64下运行,也就是默认安装了桌面和显卡驱动程序。后来打算把cuda驱动卸载了重新来一次
命令如下:
cuda_10.xxxx_linux.run --uninstall --silent
在网上找到了方法解决缺少libcuda.so.1
sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt update sudo apt install nvidia-384
安装日志:
Building dependency tree Reading state information... Done The following additional packages will be installed: bbswitch-dkms dkms lib32gcc1 libc-dev-bin libc6 libc6-dbg libc6-dev libc6-i386 libcuda1-384 libdrm-amdgpu1 libdrm-common libdrm2 libjansson4 libllvm6.0 libvdpau1 libxnvctrl0 mesa-vdpau-drivers nvidia-opencl-icd-384 nvidia-prime nvidia-settings ocl-icd-libopencl1 screen-resolution-extra vdpau-driver-all Suggested packages: bumblebee glibc-doc libvdpau-va-gl1 nvidia-vdpau-driver nvidia-legacy-340xx-vdpau-driver The following NEW packages will be installed: bbswitch-dkms dkms lib32gcc1 libc6-i386 libcuda1-384 libjansson4 libllvm6.0 libvdpau1 libxnvctrl0 mesa-vdpau-drivers nvidia-384 nvidia-opencl-icd-384 nvidia-prime nvidia-settings ocl-icd-libopencl1 screen-resolution-extra vdpau-driver-all The following packages will be upgraded: libc-dev-bin libc6 libc6-dbg libc6-dev libdrm-amdgpu1 libdrm-common libdrm2 7 upgraded, 17 newly installed, 0 to remove and 518 not upgraded. Need to get 959 kB/109 MB of archives. After this operation, 459 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu xenial/main amd64 nvidia-settings amd64 418.56-0ubuntu0~gpu16.04.1 [959 kB] Fetched 232 kB in 55s (4,172 B/s) Preconfiguring packages ... (Reading database ... 180724 files and directories currently installed.) Preparing to unpack .../libc6-dbg_2.23-0ubuntu11_amd64.deb ... Unpacking libc6-dbg:amd64 (2.23-0ubuntu11) over (2.23-0ubuntu10) ... Preparing to unpack .../libc6-dev_2.23-0ubuntu11_amd64.deb ... Unpacking libc6-dev:amd64 (2.23-0ubuntu11) over (2.23-0ubuntu10) ... Preparing to unpack .../libc-dev-bin_2.23-0ubuntu11_amd64.deb ... Unpacking libc-dev-bin (2.23-0ubuntu11) over (2.23-0ubuntu10) ... Preparing to unpack .../libc6_2.23-0ubuntu11_amd64.deb ... Unpacking libc6:amd64 (2.23-0ubuntu11) over (2.23-0ubuntu10) ... Setting up libc6:amd64 (2.23-0ubuntu11) ... Processing triggers for libc-bin (2.23-0ubuntu10) ... Processing triggers for man-db (2.7.5-1) ... (Reading database ... 180724 files and directories currently installed.) Preparing to unpack .../libdrm-common_2.4.91-2~16.04.1_all.deb ... Unpacking libdrm-common (2.4.91-2~16.04.1) over (2.4.83-1~16.04.1) ... Preparing to unpack .../libdrm2_2.4.91-2~16.04.1_amd64.deb ... Unpacking libdrm2:amd64 (2.4.91-2~16.04.1) over (2.4.83-1~16.04.1) ... Selecting previously unselected package dkms. Preparing to unpack .../dkms_2.2.0.3-2ubuntu11.8_all.deb ... Unpacking dkms (2.2.0.3-2ubuntu11.8) ... Selecting previously unselected package libc6-i386. Preparing to unpack .../libc6-i386_2.23-0ubuntu11_amd64.deb ... Unpacking libc6-i386 (2.23-0ubuntu11) ... Selecting previously unselected package lib32gcc1. Preparing to unpack .../lib32gcc1_1%3a6.0.1-0ubuntu1_amd64.deb ... Unpacking lib32gcc1 (1:6.0.1-0ubuntu1) ... Selecting previously unselected package nvidia-384. Preparing to unpack .../nvidia-384_384.130-0ubuntu0.16.04.2_amd64.deb ... Unpacking nvidia-384 (384.130-0ubuntu0.16.04.2) ... Selecting previously unselected package libcuda1-384. Preparing to unpack .../libcuda1-384_384.130-0ubuntu0.16.04.2_amd64.deb ... Unpacking libcuda1-384 (384.130-0ubuntu0.16.04.2) ... Preparing to unpack .../libdrm-amdgpu1_2.4.91-2~16.04.1_amd64.deb ... Unpacking libdrm-amdgpu1:amd64 (2.4.91-2~16.04.1) over (2.4.83-1~16.04.1) ... Selecting previously unselected package libjansson4:amd64. Preparing to unpack .../libjansson4_2.7-3ubuntu0.1_amd64.deb ... Unpacking libjansson4:amd64 (2.7-3ubuntu0.1) ... Selecting previously unselected package libllvm6.0:amd64. Preparing to unpack .../libllvm6.0_1%3a6.0-1ubuntu2~16.04.1_amd64.deb ... Unpacking libllvm6.0:amd64 (1:6.0-1ubuntu2~16.04.1) ... Selecting previously unselected package libvdpau1:amd64. Preparing to unpack .../libvdpau1_1.2-0ubuntu0~gpu16.04.1_amd64.deb ... Unpacking libvdpau1:amd64 (1.2-0ubuntu0~gpu16.04.1) ... Selecting previously unselected package libxnvctrl0:amd64. Preparing to unpack .../libxnvctrl0_418.56-0ubuntu0~gpu16.04.1_amd64.deb ... Unpacking libxnvctrl0:amd64 (418.56-0ubuntu0~gpu16.04.1) ... Selecting previously unselected package mesa-vdpau-drivers:amd64. Preparing to unpack .../mesa-vdpau-drivers_18.0.5-0ubuntu0~16.04.1_amd64.deb ... Unpacking mesa-vdpau-drivers:amd64 (18.0.5-0ubuntu0~16.04.1) ... Selecting previously unselected package ocl-icd-libopencl1:amd64. Preparing to unpack .../ocl-icd-libopencl1_2.2.8-1_amd64.deb ... Unpacking ocl-icd-libopencl1:amd64 (2.2.8-1) ... Selecting previously unselected package nvidia-opencl-icd-384. Preparing to unpack .../nvidia-opencl-icd-384_384.130-0ubuntu0.16.04.2_amd64.deb ... Unpacking nvidia-opencl-icd-384 (384.130-0ubuntu0.16.04.2) ... Selecting previously unselected package bbswitch-dkms. Preparing to unpack .../bbswitch-dkms_0.8-3ubuntu1_amd64.deb ... Unpacking bbswitch-dkms (0.8-3ubuntu1) ... Selecting previously unselected package nvidia-prime. Preparing to unpack .../nvidia-prime_0.8.2_amd64.deb ... Unpacking nvidia-prime (0.8.2) ... Selecting previously unselected package screen-resolution-extra. Preparing to unpack .../screen-resolution-extra_0.17.1.1~16.04.1_all.deb ... Unpacking screen-resolution-extra (0.17.1.1~16.04.1) ... Selecting previously unselected package nvidia-settings. Preparing to unpack .../nvidia-settings_418.56-0ubuntu0~gpu16.04.1_amd64.deb ... Unpacking nvidia-settings (418.56-0ubuntu0~gpu16.04.1) ... Selecting previously unselected package vdpau-driver-all:amd64. Preparing to unpack .../vdpau-driver-all_1.2-0ubuntu0~gpu16.04.1_amd64.deb ... Unpacking vdpau-driver-all:amd64 (1.2-0ubuntu0~gpu16.04.1) ... Processing triggers for libc-bin (2.23-0ubuntu10) ... Processing triggers for man-db (2.7.5-1) ... Processing triggers for ureadahead (0.100.0-19) ... Processing triggers for doc-base (0.10.7) ... Processing 1 added doc-base file... Processing triggers for dbus (1.10.6-1ubuntu3.3) ... Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ... Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ... Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160824-0ubuntu1) ... Rebuilding /usr/share/applications/bamf-2.index... Processing triggers for mime-support (3.59ubuntu1) ... Setting up libc6-dbg:amd64 (2.23-0ubuntu11) ... Setting up libc-dev-bin (2.23-0ubuntu11) ... Setting up libc6-dev:amd64 (2.23-0ubuntu11) ... Setting up libdrm-common (2.4.91-2~16.04.1) ... Setting up libdrm2:amd64 (2.4.91-2~16.04.1) ... Setting up dkms (2.2.0.3-2ubuntu11.8) ... Setting up libc6-i386 (2.23-0ubuntu11) ... Setting up lib32gcc1 (1:6.0.1-0ubuntu1) ... Setting up nvidia-384 (384.130-0ubuntu0.16.04.2) ... update-alternatives: using /usr/lib/nvidia-384/ld.so.conf to provide /etc/ld.so.conf.d/x86_64-linux-gnu_GL.conf (x86_64-linux-gnu_gl_conf) in auto mode update-alternatives: using /usr/lib/nvidia-384/ld.so.conf to provide /etc/ld.so.conf.d/x86_64-linux-gnu_EGL.conf (x86_64-linux-gnu_egl_conf) in auto mode update-alternatives: using /usr/lib/nvidia-384/alt_ld.so.conf to provide /etc/ld.so.conf.d/i386-linux-gnu_GL.conf (i386-linux-gnu_gl_conf) in auto mode update-alternatives: using /usr/lib/nvidia-384/alt_ld.so.conf to provide /etc/ld.so.conf.d/i386-linux-gnu_EGL.conf (i386-linux-gnu_egl_conf) in auto mode update-alternatives: using /usr/share/nvidia-384/glamor.conf to provide /usr/share/X11/xorg.conf.d/glamoregl.conf (glamor_conf) in auto mode update-initramfs: deferring update (trigger activated) INFO:Enable nvidia-384 DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad Adding system user `nvidia-persistenced' (UID 122) ... Adding new group `nvidia-persistenced' (GID 129) ... Adding new user `nvidia-persistenced' (UID 122) with group `nvidia-persistenced' ... Not creating home directory `/'. Loading new nvidia-384-384.130 DKMS files... First Installation: checking all kernels... Building only for 4.13.0-36-generic Building for architecture x86_64 Building initial module for 4.13.0-36-generic Done. nvidia_384: Running module version sanity check. - Original module - No original module exists within this kernel - Installation - Installing to /lib/modules/4.13.0-36-generic/updates/dkms/ nvidia_384_modeset.ko: Running module version sanity check. - Original module - No original module exists within this kernel - Installation - Installing to /lib/modules/4.13.0-36-generic/updates/dkms/ nvidia_384_drm.ko: Running module version sanity check. - Original module - No original module exists within this kernel - Installation - Installing to /lib/modules/4.13.0-36-generic/updates/dkms/ nvidia_384_uvm.ko: Running module version sanity check. - Original module - No original module exists within this kernel - Installation - Installing to /lib/modules/4.13.0-36-generic/updates/dkms/ depmod....... DKMS: install completed. Setting up libcuda1-384 (384.130-0ubuntu0.16.04.2) ... Setting up libdrm-amdgpu1:amd64 (2.4.91-2~16.04.1) ... Setting up libjansson4:amd64 (2.7-3ubuntu0.1) ... Setting up libllvm6.0:amd64 (1:6.0-1ubuntu2~16.04.1) ... Setting up libvdpau1:amd64 (1.2-0ubuntu0~gpu16.04.1) ... Setting up libxnvctrl0:amd64 (418.56-0ubuntu0~gpu16.04.1) ... Setting up mesa-vdpau-drivers:amd64 (18.0.5-0ubuntu0~16.04.1) ... Setting up ocl-icd-libopencl1:amd64 (2.2.8-1) ... Setting up nvidia-opencl-icd-384 (384.130-0ubuntu0.16.04.2) ... Setting up bbswitch-dkms (0.8-3ubuntu1) ... Loading new bbswitch-0.8 DKMS files... First Installation: checking all kernels... Building only for 4.13.0-36-generic Building initial module for 4.13.0-36-generic Done. bbswitch: Running module version sanity check. - Original module - No original module exists within this kernel - Installation - Installing to /lib/modules/4.13.0-36-generic/updates/dkms/ depmod.... DKMS: install completed. Setting up nvidia-prime (0.8.2) ... Setting up screen-resolution-extra (0.17.1.1~16.04.1) ... Setting up nvidia-settings (418.56-0ubuntu0~gpu16.04.1) ... Setting up vdpau-driver-all:amd64 (1.2-0ubuntu0~gpu16.04.1) ... Processing triggers for libc-bin (2.23-0ubuntu10) ... Processing triggers for initramfs-tools (0.122ubuntu8.10) ... update-initramfs: Generating /boot/initrd.img-4.13.0-36-generic Processing triggers for ureadahead (0.100.0-19) ... Processing triggers for dbus (1.10.6-1ubuntu3.3) ...
至此,我的python程序运行不报错了。但是在虚拟机里装程序,不能使用宿主机的gpu,最终还得在物理机安装。
转载自:https://blog.csdn.net/LYKymy/article/details/94829946?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
如果不是桌面版本,解决方法可能不一样