Setup to Interface C++ with Python scripts#
Last revised by S. Pattamudu-Manoharan on 2025 FEB 4
Mac Setup Guide#
Check if Clang is already installed * Run the following command:
clang --versionIf Clang is installed, it will display the version details.
If not, proceed to the installation steps below.
Install Clang * Install Xcode Command Line Tools (which include Clang) by running:
xcode-select --install* Follow the on-screen instructions to complete the installation.Verify Installation * After installation, check if Clang is properly installed:
clang --version* This should display the Clang version.Install Required Python Packages to interface with C++ * Install setuptools, wheel, and pybind11:
pip install setuptools wheel pybind11Install Eigen * Install Eigen using Homebrew:
brew install eigenVerify Eigen Installation * Run:
brew list eigen* Copy the path that contains theincludefolder.Update Setup.py file * Paste the copied Eigen path into the
setup.pyfile.Build the Python Package * Run:
python setup.py buildAdd the C++ build files path to your environment, follow these steps: Append the following line to your Bash profile configuration file:
Warning
Avoid exposing sensitive information when sharing your screen. The command
nano ~/.bash_profileopens a file that may contain credentials, API keys, or environment variables.To open the .bash_profile, run:
nano ~/.bash_profileAdd the following line:
export PYTHONPATH='$PYTHONPATH:/your_cpp_build_path'Update ‘your_cpp_build_path’ with the path of the directory that contains the compiled .so files.Click on control + X and then Y to save and exit the file.
Apply the changes by running this command:
source ~/.bash_profile
Run the Python Test Code * Finally, execute the test script
"CPP_setup_verification.py"to verify the setup.
Windows Setup Guide#
Install C++ Build Tools for Visual Studio * Download and install from https://visualstudio.microsoft.com/downloads/?q=build+tools
During installation, ensure to select “C++ Development” from the available options.
This will download and install the necessary components, approximately 6.7GB in size.
These tools are required for building and compiling C++ extensions.
Install Required Python Packages * Run the following command:
pip install setuptools wheelC++ Extension Configuration
Download Eigen * Get the latest version from: https://eigen.tuxfamily.org/dox/GettingStarted.html
Store Eigen in a Safe Location * Extract and place it in a secure directory, such as:
C:\Program Files\EigenSet the Eigen Path in Environment Variables * Add the Eigen include directory to the environment variable:
Include Eigen Directory in the Setup.py file *
eigen_include_dir = "C:\your_eigen_folder_path"Set the C++ Build Path in Environment Variables * Add the C++ build path to the environment variable:
C:Users/your_build_path/Build the Python Package * Run:
bash python setup.py buildRun the Python Test Code * Finally, execute the
cpp_test.pyscript to verify the setup.