GithubHelp home page GithubHelp logo

pycextension's Introduction

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.

Prerequisite

  • Python
  • setuptools
  • pip
  • wheel
build
cd PyCExtension/MyCLib1
python setup.py build
python setup.py install
Windows Installer Exe
cd PyCExtension/MyCLib1
python setup.py bdist_wininst
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

un/install the package

# to uninstall 
pip uninstall MyCLib1

# to install
pip install MyCLib1

Reference Links


Creating extension

Following source of information may help you to creat python native extension.

Debug (so far all windows)

[Packaging and Distributing]

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/

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/

Distribution format

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.

Python Tag

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

ABI Tag

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.

Platform Tag

The platform tag is simply distutils.util.get_platform() with all hyphens - and periods . replaced with underscore
win32
linux_i386
linux_x86_64

Setup

pip install wheel 
pip install twine 
pip install tox 
pip install cookiecutter

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

Continuous integration

VS setting for the C proj (MyCLib1) to build native lib

System Env

SET MY_PY_DIR=C:\Dev\Anaconda3

MyCLib1 project properties -> Configuration Properties

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

pycextension's People

Contributors

msatyan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.