This is a template for a Python C module. It is a simple example that shows how to create a Python module in C and C++.
- Python C/C++ module
- Python module tests
- setup.pyfor building and installing the module
- pycmtemplatecommand line script for running the module in anywhere
- pycmtemplatePython module for importing the module
- init.shfor initializing the project
- clean.shfor cleaning up the project
- Clone the repository
- init.shto initialize the project
- source venv/bin/activateto activate the virtual environment
- pip install .for installing the module or- pip install -e .for installing the module in editable mode
- python -m teststo run the tests
- python -m pycmtemplateor directly run- pycmtemplateto run the module from the command line
Required configurations are in the setup.py file. The init.sh script initializes the project by creating virtual environment and installing the required packages.
To build the module, run the following command:
python setup.py buildThe build command will create a build directory with the compiled module.
To install the module after building via setup.py, run the following command:
python setup.py installTo build and install the module with pip, run the following command:
pip install .To install the module in editable mode, run the following command:
pip install -e .Note: editable mode is useful for development purposes. It allows you to modify the source code and see the changes without reinstalling the module. However, it does not work with C/C++ modules.
After installing the module, you can run it from the command line:
python -m pycmtemplateor directly:
pycmtemplateTo run the tests:
python -m testsTo clean up the project, run the following command:
./clean.shThe clean.sh script removes the build, dist, pycmtemplate.egg-info and venv directories, as well as the __pycache__ directories.