Original Blog: Doi Tech Team
Link: https://blog.doiduoyi.com/authors/1584446358138
Original Intent: Record the learning experiences of the excellent Doi Tech Team
Environment¶
- System: Ubuntu 16.0.4 (64-bit)
- Processor: Intel(R) Celeron(R) CPU
- Memory: 8G
- Environment: Python 2.7
Installation on Windows System¶
PaddlePaddle does not currently support Windows. If you attempt to install PaddlePaddle directly on Windows, you will receive an error indicating the package is not found. For Windows users, we recommend two solutions:
1. Use Docker containers on Windows to install PaddlePaddle via Docker images.
2. Install a virtual machine (e.g., VirtualBox) on Windows and then install Ubuntu within the VM.
This article is based on PaddlePaddle 0.11.0 and Python 2.7.
Installing Docker Containers on Windows¶
First, download Docker Toolbox, which includes Docker and VirtualBox:
https://docs.docker.com/toolbox/toolbox_install_windows/
After downloading, double-click the installer to start the installation:
- Select Installation Path: Use the default path.
- Dependencies: Ensure all required components are checked (e.g., Git, VirtualBox).
- Create Desktop Shortcuts: Leave default settings.
- Complete Installation: Wait for the process to finish.
Note: If Docker starts and gets stuck downloading boot2docker.iso, manually copy the pre-packaged ISO from the Docker Toolbox installation directory to the cache folder:
C:\Program Files\Docker Toolbox\boot2docker.iso → C:\Users\YourUsername\.docker\machine\cache\
Double-click the Docker Quickstart Terminal shortcut. If successful, you will see the Docker logo and a command prompt.
Installing Ubuntu on Windows¶
-
Install VirtualBox:
Download from https://www.virtualbox.org/. -
Create a Virtual Machine:
- Click “New” and follow the wizard to set memory (2G minimum for training), create a VDI disk (dynamically allocated, 20G+ recommended), and select the Ubuntu 16.04 ISO image. -
Configure and Install:
- Disable the floppy drive in “System” settings.
- Start the VM and install Ubuntu with Chinese language support, download updates during installation, and select “Erase disk and install Ubuntu”.
- Set a user name and password, then wait for completion. -
Post-Installation:
Remove the Ubuntu ISO from the storage settings to avoid reuse. For Windows 10 users, consider using the built-in WSL (Windows Subsystem for Linux).
Installation via pip¶
If pip is not installed, install it first:
sudo apt install python-pip
Verify pip version (must be ≥9.0.0):
pip --version
Upgrade pip if necessary:
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
Install PaddlePaddle using Aliyun’s mirror for faster download:
pip install paddlepaddle==0.11.0 -i https://mirrors.aliyun.com/pypi/simple/
Test Installation:
import paddle.v2 as paddle
No errors indicate success.
Installation via Docker¶
Docker provides an isolated environment. Install Docker first:
sudo apt-get install docker.io
Verify Docker installation:
docker --version
Pull the PaddlePaddle image:
docker pull hub.baidubce.com/paddlepaddle/paddle
After downloading, run the container to test PaddlePaddle.
Compiling from Source Code¶
If you need a custom build (e.g., without AVX support), follow these steps:
Local Compilation¶
1. Install Dependencies¶
| Dependency | Version | Notes |
|---|---|---|
| GCC | ≥4.8.2 | Recommended: sudo apt-get install gcc-4.9 |
| CMake | ≥3.2 | Download and build from source: |
wget https://cmake.org/files/v3.8/cmake-3.8.0.tar.gz
tar -zxvf cmake-3.8.0.tar.gz
cd cmake-3.8.0
./bootstrap && make && sudo make install
``` |
| Python | 2.7.x | `sudo apt-get install python-pip` |
| NumPy | ≥1.11 | `sudo apt-get install python-numpy` |
| SWIG | ≥2.0 | `sudo apt-get install swig` |
| Go | ≥1.8 | Optional: `sudo apt-get install golang` |
### 2. Clone and Build PaddlePaddle
```bash
git clone https://github.com/PaddlePaddle/Paddle.git
cd Paddle
git checkout release/0.11.0
mkdir build && cd build
cmake .. -DWITH_GPU=OFF -DWITH_AVX=OFF -DWITH_TESTING=OFF
make -j4 # Use 4 CPU cores
Install the generated wheel package:
cd build/python/dist
pip install *.whl
Compiling via Docker¶
Simplify compilation by using the official Paddle Docker image:
git clone https://github.com/PaddlePaddle/Paddle.git
cd Paddle
git checkout release/0.11.0
docker run -v $PWD:/paddle -it hub.baidubce.com/paddlepaddle/paddle:latest-dev /bin/bash
Inside the container:
cd /paddle
mkdir build && cd build
cmake .. -DWITH_GPU=OFF -DWITH_AVX=OFF -DWITH_TESTING=OFF
make -j4
exit
The wheel package will be in Paddle/build/python/dist. Install it on the host:
pip install build/python/dist/*.whl
Building a Custom Docker Image¶
To create a Docker image with your specific build options:
git clone https://github.com/PaddlePaddle/Paddle.git
cd Paddle
git checkout release/0.11.0
docker build -t paddle:dev .
Run the build process within the container:
docker run --rm -e WITH_GPU=OFF -e WITH_AVX=OFF -v $PWD:/paddle paddle:dev
Testing the Installation¶
Run the official UCI Housing example to verify:
Create housing.py:
import paddle.v2 as paddle
paddle.init(use_gpu=False, trainer_count=1)
x = paddle.layer.data(name='x', type=paddle.data_type.dense_vector(13))
y_predict = paddle.layer.fc(input=x, size=1, act=paddle.activation.Linear())
probs = paddle.infer(
output_layer=y_predict,
parameters=paddle.dataset.uci_housing.model(),
input=[item for item in paddle.dataset.uci_housing.test()()])
for i in xrange(len(probs)):
print 'Predicted price: ${:,.2f}'.format(probs[i][0] * 1000)
Run on Local Machine:
python housing.py
Run on Docker:
docker run -v $PWD:/work -w /work -p 8899:8899 hub.baidubce.com/paddlepaddle/paddle python housing.py
Final Notes¶
- AVX Support Check:
if cat /proc/cpuinfo | grep -i avx; then echo Yes; else echo No; fi
- Dynamic Library Issues: If
libmkldnn.so.0is missing, runldconfig.
Project Code¶
GitHub: https://github.com/yeyupiaoling/LearnPaddle
References¶
Next Chapter: My PaddlePaddle Learning Notes II — MNIST Handwritten Digit Recognition¶
Note: This translation preserves the original structure and code blocks while ensuring technical accuracy.