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 modulepycmtemplatecommand line script for running the module in anywherepycmtemplatePython module for importing the moduleinit.shfor initializing the projectclean.shfor cleaning up the project
- Clone the repository
init.shto initialize the projectsource venv/bin/activateto activate the virtual environmentpip install .for installing the module orpip install -e .for installing the module in editable modepython -m teststo run the testspython -m pycmtemplateor directly runpycmtemplateto 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.