记录实验室机器使用 Virtualenv 安装 TensorFlow 的过程。过程来自 TensorFlow 官网
**Tips: **这里不需要使用命令:
sudo apt-get install cuda-command-line-tools
安装libcupti-dev
。因为 CUDA 9.0 已经包含该库文件了。可以使用locate libcupti.so
来查看该文件。
安装步骤
1. 安装 pip 和 Virtualenv
$ sudo apt-get install python-pip python-dev python-virtualenv # for Python 2.7
$ sudo apt-get install python3-pip python3-dev python3-virtualenv # for Python 3.n
2. 创建一个 Virtualenv 环境
$ virtualenv --system-site-packages ~/tensorFlow # for Python 2.7
$ virtualenv --system-site-packages -p python3 ~/tensorFlow # for python3.n
3. 启动刚创建的 Virtualenv 环境
$ source ~/tensorFlow/bin/activate # bash, sh, ksh, or zsh
$ source ~/tensorFlow/bin/activate.csh # csh or tcsh
启动环境之后你会发现命令行提示符前面会带有(TensorFlow)的标记如下:
(tensorflow) $ pwd
代表虚拟环境创建成功。
4. 确保你的 pip 为 8.1 以上的版本
(tensorflow) $ easy_install -U pip
5. 选择以下之一的命令来安装 TensorFlow 到 ~/tensorflow 虚拟环境中
因为一些原因,网络可能不太好。这里建议 pip 配置清华大学的源来安装,会快很多。
(tensorFlow)$ pip install --upgrade tensorflow # for python 2.7
(tensorFlow)$ pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow # for python 3.n
(tensorFlow)$ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow-gpu # for python 2.7 with GPU
(tensorFlow)$ pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow-gpu # for Python 3.n with GPU
如果你的机器硬件驱动方面没问题,以上安装过程没有产生错误,那么 TensorFlow 就安装成功了。