Why can I not create a wheel in python?
Install the wheel
package first:
pip install wheel
The documentation isn't overly clear on this, but "the wheel project provides a bdist_wheel command for setuptools" actually means "the wheel package...". What is the meaning of Failed building wheel for X in pip install?
Since, nobody seem to mention this apart myself. My own solution to the above problem is most often to make sure to disable the cached copy by using: pip install <package> --no-cache-dir
.
What needs to be in a setup.py to create a wheel?
You don't need to write anything special in your setup.py
to be able to create a wheel. As long as your setup.py
is using setuptools
(which it should be anyway), you just write a normal setup.py
, install the wheel
package on your system, and run python setup.py bdist_wheel
.
How to build py3-none-any wheels for a project with an optional C extension?
One possible solution is to use an environment variable in setup.py
to decide
whether to set ext_modules
to an empty list of a list of setuptools.Extension
pyproject.toml
[build-system]
requires = ["setuptools", "wheel", "cython"]
build-backend = "setuptools.build_meta"
setup.py
from setuptools import setup, Extension
import os
if 'ONLY_PURE' in os.environ:
ext_modules = []
else:
module1 = Extension('helloworld', sources = ['helloworld.pyx'])
ext_modules = [module1]
setup(ext_modules=ext_modules)
setup.cfg
[metadata]
name = mypackage
version = 0.0.1
[options]
py_modules = mypackage
mypackage.py
try:
import helloworld
except ImportError:
print('hello pure python')
helloworld.pyx
print("hello extension")
To build with extension:
$ pip install build
...
$ python -m build
...
$ ls dist/
mypackage-0.0.1-cp39-cp39-linux_x86_64.whl mypackage-0.0.1.tar.gz
To build without extension
$ pip install build
...
$ ONLY_PURE='a nonempty string' python -m build
...
$ ls dist/
mypackage-0.0.1-py3-none-any.whl mypackage-0.0.1.tar.gz
Related Topics
Hide Chromedriver Console in Python
How to Crop an Image Using Pil
How to Limit the Maximum Value of a Numeric Field in a Django Model
How to Get All the Request Headers in Django
How to Use Asyncio with Existing Blocking Library
How to Assign the Same Value to Multiple Keys in a Dict Object at Once
How to Print a Dictionary Line by Line in Python
How to Get a List of Keywords in Python
Append Dataframe to Excel with Pandas
What's the Best Way to Store a Phone Number in Django Models
Numpy Array Initialization (Fill with Identical Values)
Difference Between 'Python Setup.Py Install' and 'Pip Install'
Filtering a Pyspark Dataframe with SQL-Like in Clause