为pip配置Python C扩展

问题描述 投票:0回答:1

我写了Python C扩展,效果很好。通过python setup.py install安装即可。但是,pip无法找到我的头文件-因此无法安装pip。

> pip install
Collecting jcalg1==1.0.1
  Downloading https://files.pythonhosted.org/packages/a1/83/08b5fc2fbd36c8ac0668ae64c05cc88f3f6bd8fe68f058b19b11a463afa1/jcalg1-1.0.1.tar.gz
Installing collected packages: jcalg1
  Running setup.py install for jcalg1 ... error
    ERROR: Command errored out with exit status 1:
(...)
src\main.cpp(7): fatal error C1083: Cannot open include file: 'jcalg1.h': No such file or directory
(...)

这是我的setup.py,头文件位于src文件夹中。

from setuptools import setup,Extension
import setuptools
from setuptools import find_packages
import pathlib

# The actual C extension
jc_module = Extension('jcalg1', include_dirs=["src"], sources = ['src\main.cpp'], libraries =["src\jcalg1_static"])

# The directory containing this file
HERE = pathlib.Path(__file__).parent

# The text of the README file
README = (HERE / "README.md").read_text()

# This call to setup() does all the work
setup(
    name="jcalg1",
    version="1.0.1",
    description="Interface to the JCALG1 compression library",
    long_description=README,
    long_description_content_type="text/markdown",
    url="https://github.com/CallMeAlexO/jcalg1",
    author="Alex Osheter",
    author_email="[email protected]",
    license="MIT",
    classifiers=[
        "License :: OSI Approved :: MIT License",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.7",
    ],
    ext_modules = [ jc_module ],
    packages=find_packages()
)
python setuptools cpython python-c-api
1个回答
0
投票

您可以在项目根目录中创建MANIFEST.in文件:

include *.h
include *.lib

然后重建软件包。它将头文件和库文件添加到您的包中。

© www.soinside.com 2019 - 2024. All rights reserved.