一、利用anaconda安裝
二、利用源碼安裝
1.安裝依賴庫
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential \
git \
libgoogle-glog-dev \
libgtest-dev \
libiomp-dev \
libleveldb-dev \
liblmdb-dev \
libopencv-dev \
libopenmpi-dev \
libsnappy-dev \
libprotobuf-dev \
openmpi-bin \
openmpi-doc \
protobuf-compiler \
python-dev \
python-pip
pip install --user \
future \
numpy \
protobuf \
typing \
hypothesis
# for Ubuntu 14.04
sudo apt-get install -y --no-install-recommends \
libgflags2 \
cmake3
# for Ubuntu 16.04
sudo apt-get install -y --no-install-recommends \
libgflags-dev \
cmake
2.克隆和建立
git clone https://github.com/pytorch/pytorch.git && cd pytorch
git submodule update --init --recursive
python setup.py install
執行git submodule update --init --recursive時,因爲git深度的影響沒辦法git完,得多執行這條命令幾次。
如果出現下面這個錯誤,重新編譯就好,即python setup.py install
3.測試
法一:
(py35_pytorch0_4_1) aibc@aibc:~$ python
Python 3.5.5 | packaged by conda-forge | (default, Jul 23 2018, 23:45:43)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>> import caffe2
>>>
表示安裝成功。
法二:
(py35_pytorch0_4_1) aibc@aibc:~$ cd ~ && python -c 'from caffe2.python import core' 2>/dev/null && echo "Success" || echo "Failure"
Success
表示安裝成功。
4.參考網址:
https://caffe2.ai/docs/getting-started.html?platform=ubuntu&configuration=compile