Before starting the build process, ensure your system meets these requirements:
- Ubuntu 22.04 LTS (fresh installation recommended)
- At least 8GB of free disk space
- Internet connection for downloading packages
- Sudo privileges
pythonOCC 7.8.1 requires the following components:
Component | Version | Purpose |
---|---|---|
Python | ≥ 3.9 | Runtime environment |
OpenCascade | 7.8.1 | Core CAD functionality |
SWIG | 4.2.1 | Interface generation |
CMake | ≥ 3.1 | Build system |
First, update your system and install required packages:
sudo apt-get update
sudo apt-get install -y \
wget \
libglu1-mesa-dev \
libgl1-mesa-dev \
libxmu-dev \
libxi-dev \
build-essential \
cmake \
libfreetype6-dev \
tk-dev \
python3-dev \
rapidjson-dev \
python3 \
git \
python3-pip \
libpcre2-dev
SWIG 4.2.1 is required but not available in Ubuntu's default repositories. Build it from source:
wget http://prdownloads.sourceforge.net/swig/swig-4.2.1.tar.gz
tar -zxvf swig-4.2.1.tar.gz
cd swig-4.2.1
./configure
make -j$(nproc)
sudo make install
Download and extract OpenCascade 7.8.1:
wget https://github.com/Open-Cascade-SAS/OCCT/archive/refs/tags/V7_8_1.tar.gz
tar -xvzf V7_8_1.tar.gz
cd OCCT-7.8.1
mkdir cmake-build
cd cmake-build
Configure and build OpenCascade:
cmake -DINSTALL_DIR=/opt/occt781 \
-DBUILD_RELEASE_DISABLE_EXCEPTIONS=OFF \
..
make -j$(nproc)
sudo make install
Add OpenCascade libraries to the system:
sudo bash -c 'echo "/opt/occt781/lib" >> /etc/ld.so.conf.d/occt.conf'
sudo ldconfig
Clone and build pythonOCC:
git clone https://github.com/tpaviot/pythonocc-core.git
cd pythonocc-core
mkdir cmake-build && cd cmake-build
# Set installation directory (optional)
PYTHONOCC_INSTALL_DIRECTORY=${PYTHONOCC_INSTALL_DIRECTORY:-/usr/local}
cmake \
-DOCCT_INCLUDE_DIR=/opt/occt781/include/opencascade \
-DOCCT_LIBRARY_DIR=/opt/occt781/lib \
-DCMAKE_BUILD_TYPE=Release \
-DPYTHONOCC_INSTALL_DIRECTORY=$PYTHONOCC_INSTALL_DIRECTORY \
..
make -j$(nproc) && sudo make install
Add OpenCascade libraries to your environment:
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/occt781/lib' >> ~/.bashrc
source ~/.bashrc
Before starting the build process, ensure your system meets these requirements:
- Windows 10 or 11 (64-bit)
- At least 10GB of free disk space
- Internet connection for downloading packages
- Administrator privileges
Component | Version | Download Link |
---|---|---|
Visual Studio | 2019 or 2022 Community | Download |
Python | ≥ 3.9 | Download |
CMake | ≥ 3.1 | Download |
Git | Latest | Download |
RapidJSON | Latest | Download |
SWIG | 4.2.1 | Download |
OpenCascade | 7.8.1 | Download |
-
Install Visual Studio 2019/2022 Community Edition:
- During installation, select "Desktop development with C++"
- Include "Windows 10 SDK" and "MSBuild"
-
Install Python 3.9 or later:
- Download and run the installer
- Check "Add Python to PATH"
- Choose "Customize installation"
- Select "pip" and "py launcher"
- Install for all users
-
Install CMake:
- Download and run the installer
- Add CMake to the system PATH for all users
-
Install Git:
- Download and run the installer
- Use Git from Windows Command Prompt
- Use OpenSSL library
-
Install SWIG:
- Download SWIG 4.2.1 for Windows
- Extract to C:\swigwin
- Add C:\swigwin to the system PATH
-
Install RapidJSON
- Clone the git repository git clone https://github.com/Tencent/rapidjson.git
Binaries for dependencies can be downloaded at https://dev.opencascade.org/resources/download/3rd-party-components
- Download OpenCascade 7.8.1 for Windows
- Extract to, for example, occt-7.8.1
If the binaries are not available, consider compiling by yourself OCCT on Windows. Refer to the official OpenCascade Technology documentation https://dev.opencascade.org/doc/overview/html/build_upgrade.html
When installing OpenCascade and third-party libraries, you should have a structure similar to the one described at https://dev.opencascade.org/doc/overview/html/index.html#intro_install_windows
C:\OpenCASCADE-7.8.1-vc10-64 ├── ffmpeg-3.3.4-gpl-64 ├── freeimage-3.17.0-vc10-64 ├── freetype-2.6.3-vc10-64 ├── occt-7.8.1 ├── qt486-vc10-64 ├── tclkit-86-64 ├── vtk-6.1.0-vc10-64 └── zlib-1.2.8-vc10-64
- Clone the repository:
git clone https://github.com/tpaviot/pythonocc-core.git
cd pythonocc-core
- Create build directory:
mkdir cmake-build
cd cmake-build
- Configure with CMake:
cmake -G "Visual Studio 16 2019" -A x64 ^
-DCMAKE_BUILD_TYPE=Release ^
-DOCCT_INCLUDE_DIR=C:\OpenCASCADE-7.8.1-vc10-64\occt-7.8.1\inc ^
-DOCCT_LIBRARY_DIR=C:\OpenCASCADE-7.8.1-vc10-64\occt-7.8.1\win64\vc14\lib ^
-DOCCT_ESSENTIALS_ROOT=C:\OpenCASCADE-7.8.1-vc10-64
..
If using CMake GUI, make sure to set these two variables before clicking the "Generate" button:
OCCT_INCLUDE_DIR=C:\OpenCASCADE-7.8.1-vc10-64\occt-7.8.1\inc
OCCT_LIBRARY_DIR=C:\OpenCASCADE-7.8.1-vc10-64\occt-7.8.1\win64\vc14\lib
- Build:
cmake --build . --config Release
- Install:
cmake --install .
To enable fast STL file loading with NumPy support:
- Install NumPy:
pip install numpy
- Add the following CMake flag during pythonOCC configuration:
-DPYTHONOCC_MESHDS_NUMPY=ON
Install additional Python packages for full functionality:
pip install svgwrite numpy numpy-stl matplotlib PyQt5
Verify the installation:
python3
>>> from OCC.Core.gp import gp_Pnt
>>> p = gp_Pnt(1., 2., 3.)
>>> p.X()
1.0
Run the complete test suite:
pip install pytest
pytest
Try the demo applications:
git clone https://github.com/tpaviot/pythonocc-demos
cd pythonocc-demos
python3 examples/core_classic_occ_bottle.py
-
Library not found errors:
sudo ldconfig
-
SWIG version mismatch:
- Ensure no other SWIG versions are installed
- Verify installation:
swig -version
-
DLL not found errors:
- Verify PATH environment variable includes OpenCascade bin directory
- Check Visual Studio installation
- if you encounter the following error:
-
DLL not found for 3rd part libraries:
If it was not done at build time, you can define the OCCT_ESSENTIALS_ROOT path at run time, by setting the env var:
setx OCCT_ESSENTIALS_ROOT "%CASROOT%\win64\vc14\bin"
- CMake configuration errors:
- Ensure all paths use backslashes
- Verify Visual Studio installation
- Check environment variables
For more examples and documentation, visit: