This is a sample Python package to demonstrate how to extent functionality of CPython by using C language routines. The Python provides flexibility, at the same time it is inherently slow. The C language extensions can act as a turbocharger for Python modules where it needs speed and efficiency.
- Python
- setuptools
- pip
- wheel
cd PyCExtension/MyCLib1
python setup.py build
python setup.py install
cd PyCExtension/MyCLib1
python setup.py bdist_wininst
- wheel
- wheel documentation
- The file format
- The reference implementation
- Py2: Writing the Setup Script
- Py3: Writing the Setup Script
pip install wheel
cd PyCExtension/MyCLib1
# Set MY_PY_DIR ENV to your python installation, eg:
SET MY_PY_DIR=C:\Dev\Anaconda3
# Wheel build
python setup.py bdist_wheel
# Install
# if you are on Python 3.7.4, then
# pip install dist\MyCLib1-<package version>-cp37-cp37m-win_amd64.whl
pip install dist/MyCLib1-3.0.7-cp37-cp37m-win_amd64.whl
# upload to PyPi
twine upload dist/*
# To check status of the upload
# https://pypi.org/project/<sampleproject>
https://pypi.org/project/MyCLib1
# to uninstall
pip uninstall MyCLib1
# to install
pip install MyCLib1
Following source of information may help you to creat python native extension.
- Debugging Python and C++ together
- Installing Debugging Symbols for Python Interpreters
- Profiling Python Code
- Packaging and Distributing Projects
- Setuptools’ documentation
- Building and Distributing Packages with Setuptools
- Automatic Script Creation
- Creating and publishing a Python package
- How to Publish Your Package on PyPI
- Uploading to PyPI
- How to submit a package to PyPI
- How to Host your Python Package on PyPI with GitHub
- Submitting a Python package with GitHub and PyPI
- Wheel: A built-package format for Python
- Packaging Your Code
- Sharing Your Labor of Love: PyPI Quick and Dirty
The wheel is a ZIP-format archive with a specially formatted filename and the .whl extension. It is designed to contain all the files for a PEP 376 compatible install in a way that is very close to the on-disk format https://pip.pypa.io/en/stable/reference/pip_wheel/
- Platform Wheels
- PEP 425 -- Compatibility Tags for Built Distributions
- PyPI - the Python Package Index
python setup.py bdist_wheel
bdist_wheel will detect that the code is not pure Python, and build a
wheel that’s named such that it’s only usable on the platform that it was built on.
For details on the naming of wheel files, see PEP 425.
https://www.python.org/dev/peps/pep-0425/
By comparing the tags it supports with the tags listed by the distribution, an installer can make an educated decision about whether to download a particular built distribution without having to read its full metadata
The wheel built package format includes these tags in its filenames, of the form
{distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl.
Other package formats may have their own conventions.
Overview
The tag format is {python tag}-{abi tag}-{platform tag}
python tag
‘py27’, ‘cp33’
abi tag
‘cp32dmu’, ‘none’
platform tag
‘linux_x86_64’, ‘any’
For example, the tag py27-none-any indicates compatible with Python 2.7 (any Python 2.7 implementation) with no abi requirement, on any platform.
The Python tag indicates the implementation and version required by a distribution. Major implementations have abbreviated codes, initially:
py: Generic Python (does not require implementation-specific features)
cp: CPython
ip: IronPython
pp: PyPy
jy: Jython
The ABI tag indicates which Python ABI is required by any included extension modules. For implementation-specific ABIs, the implementation is abbreviated in the same way as the Python Tag, e.g. cp33d would be the CPython 3.3 ABI with debugging.
The CPython stable ABI is abi3 as in the shared library suffix.
The platform tag is simply distutils.util.get_platform() with all hyphens - and periods . replaced with underscore
win32
linux_i386
linux_x86_64
pip install wheel
pip install twine
pip install tox
pip install cookiecutter
http://cookiecutter.readthedocs.io/en/latest/usage.html https://github.com/DerThorsten/xtensor-python-cookiecutter-v2 https://www.pydanny.com/cookie-project-templates-made-easy.html
System Env
SET MY_PY_DIR=C:\Dev\Anaconda3
General
1) Configuration Type : Dynamic Library (.dll)
2) Appy Change by clicking the Apply button
3) Target Extension change from .dll to .pyd
C/C++
# All Platforms
Additional Include Directories : $(MY_PY_DIR)\include
Linker
# All Platforms
Additional Library Directories : $(MY_PY_DIR)\libs