本文是2017.1月份的时候安装的步骤, 现在可能有些已经不适用, 请大家注意鉴别.
修改pip源
在/HOME里创建一个文件(存在的话就直接修改,反正不管有没有都执行下面的代码, 不存在的话会自动创建).
cd $HOME
mkdir .pip
cd .pip
sudo gedit pip.conf
在里面添加
[global]
index-url = https://pypi.doubanio.com/simple/
[install]
trusted-host=pypi.doubanio.com
disable-pip-version-check = true
timeout = 6000
安装virtualenv
Ubuntu 16.04: How to install OpenCV
目的是把Python安装进这个虚拟环境里, 从而不影响本机的Python环境
$ sudo pip install virtualenv virtualenvwrapper //装了两个东西
$ sudo rm -rf ~/get-pip.py ~/.cache/pip //这句我没执行 可能是删除一些安装后的残留文件吧
Once we have virtualenv and virtualenvwrapper installed, we need to update our ~/.bashrc file to include the following lines at the bottom of the file:
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
The ~/.bashrc file is simply a shell script that Bash runs whenever you launch a new terminal. You normally use this file to set various configurations. In this case, we are setting an environment variable called WORKON_HOME to point to the directory where our Python virtual environments live. We then load any necessary configurations from virtualenvwrapper .
To update your ~/.bashrc file simply use a standard text editor. I would recommend using nano , vim , or emacs . You can also use graphical editors as well, but if you’re just getting started, nano is likely the easiest to operate.
After editing our ~/.bashrc file, we need to reload the changes:
$ source ~/.bashrc
Note: Calling source on .bashrc only has to be done once for our current shell session. Anytime we open up a new terminal, the contents of .bashrc will be automatically executed (including our updates).
Now that we have installed virtualenv and virtualenvwrapper , the next step is to actually create the Python virtual environment — we do this using the mkvirtualenv command.
But before executing this command, you need to make a choice: Do you want to use Python 2.7 or Python 3?
The outcome of your choice will determine which command you run in the following section.
//Python2:
$ mkvirtualenv yourEnvName -p python2
//Python3:
$ mkvirtualenv yourEnvName -p python3
进入虚拟环境:
$ workon yourEnvName
退出虚拟环境:
$ deactivate
安装CUDA
见<安装mxnet.md>
安装CuDNN
Ubuntu 16.04 Cuda7.5/Cuda8.0 tensorflow-gpu
同学给我了’cudnn-8.0-linux-x64-v5.1.tgz’. 解压到/HOME里, 然后Terminal执行:
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
安装Tensorflow
这里我同学直接给我了’tensorflow_gpu-0.12.1-cp35-cp35m-linux_x86_64.whl’, 所以没有下.
下载的话: Github: tensorflow/tensorflow. 在’Installation’里选择对应的版本(注意选GPU, 不要CPU-only).
注意上面安装了virtualenv并创建了Python3的环境, 因此我想让tensorflow使用Python3的环境, 所以首先要进入虚拟环境:
workon yourEnvName
再在虚拟环境里安装Tensorflow:
pip install tensorflow_gpu-0.12.1-cp35-cp35m-linux_x86_64.whl
安装后测试:
import Tensorflow as tf
tf.InteractiveSession()
正常执行就成功了.
修改pycharm.sh
如果使用pycharm的话,进入pycharm根目录的bin/,以便使其能用的了TF.
打开pycharm.sh,然后在第180行左右插入:
LD_LIBRARY_PATH="/usr/local/cuda/lib64" #先找到下面
LD_LIBRARY_PATH="$IDE_BIN_HOME:$LD_LIBRARY_PATH" "$JAVA_BIN" #pycharm.py里本来就有.先找到这行, 在上面加上面那句.