docker 配置tensorflow环境

 1.首先启动一个最小化的ubuntu系统

docker run -it ubuntu

2.安装python3,pip3等必须环境

#更新apt-get库,这样才能安装python
#最小化的ubuntu是没有sudo命令的
apt-get update
apt-get install python3 python3-pip
#更新pip
pip3 install --upgrade pip

3.安装支持gpu的tensorflow

pip3 install tensorflow-gpu

   安装完之后,试着导入。遇到了报错。 libcublas.so.9.0: cannot open shared object file: No such file or directory

    这个的原因是显卡驱动没有安装好。

 4.基于Anaconda的安装

apt-get install wget
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.1.0-Linux-x86_64.sh
#安装anaconda
apt-get install bzip2
sh Ana*
conda create -name tensorflow python=3.6
source activate tensorflow
pip install tensorflow-gpu

5.安装cuda

在NVIDIA官网上下好CUDA的deb包之后,将其加入dpkg包。

dpkg -i cuda*
apt-get update
apt-get install cuda
安装的时候,遇到了 Unable to connect to 172.17.0.111:http:的报错。这个报错一般是网络不好导致的,重试几次就可以了。

之后设置环境变量

export PATH=/usr/local/cuda-9.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64/${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

6.安装NVIDIA驱动

从官网上下合适驱动的run文件,接着执行run文件。

安装NVIDIA驱动报错,

NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

Failed to initialize NVML: Unknown Error的报错

以上这两个经过了很多次尝试,还是解决不好。

最后问了同学,才知道虚拟机上不能装NVIDIA驱动。我之前所有的操作都是在docker上执行的。

7.从源码安装Tensorflow

从源码安装,下载源码。

apt-get update
apt-get install unzip
unzip tensorflow*

安装bazel

如果是update-initramfs 命令找不到,试一下man update-initramfs 命令,如果是No manual entry for update-initramfs,则说明没有安装initramfs-tools,用apt-get install 安装一下

8.安装的时候遇到的一些问题

bash: add-apt-repository: command not found的报错:apt-get install software-properties-common


猜你喜欢

转载自blog.csdn.net/ximingren/article/details/79902520