Cythonize 将 .so 文件安装到错误的位置
Cythonize installs .so files to wrong location
我想问一个关于如何使用 Cython、setuptools 扩展等配置 setup.py
的问题。我正在尝试使用 Cython.Distutils
的 build_ext
对子模块进行 cythonize。但问题不在于 Cython.Distutils
的扩展模块(如果存在),因为它未加载。只有 build_ext
。所以我在列表中创建了一个 setuptools.extension
Extension,然后 cythonize Extension 对象的列表。列表中只有一个 Extension,如下所示。
Extension("distance", ["kmerdb/distance.pyx"], include_dirs=[np.get_include()])
我尝试了不同的安装方法,从 python setup.py install
到 pip install -e .
生成 wheel 文件并安装 wheel。我找不到任何有用的东西...
好的,所以我对这个过程知之甚少,这可能就是我挂断电话的原因,但我已经搜索了整个网站,但没有成功。就这样吧。
我运行下面的shell脚本在本地安装我的包,它工作正常。问题是安装没有将 .so
和 .py
文件移动到我要导出的 kmerdb
模块中。有什么建议么?谢谢
>python setup.py sdist bdist_wheel
>/bin/auditwheel repair --plat manylinux2014_x86_64 dist/kmerdb-*linux_x86_64.whl
>mv wheelhouse/* dist
>rm dist/*linux_x86_64.whl
>pip install dist/kmerdb-*-manylinux2014_x86_64.whl
>ls ~/.pyenv/versions/kdb/lib/python3.10/site-packages/kmerdb-0.6.5-py3.10-linux-x86_64.egg/
distance.cpython-310-x86_64-linux-gnu.so distance.py kmerdb ...
同样,文件 distance.cpython-310-x86_64-linux-gno.so
没有移入 kmerdb
模块,我的 Python 包,我正在尝试在本地安装并为 .whl
配置上传到 PyPI。
Python 3.10.1 (main, Jan 1 2022, 21:28:19) [GCC 11.1.0] on linux
Cython==0.29.26
setup.py
Extension("distance", ["kmerdb/distance.pyx"], include_dirs=[np.get_include()], define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],),
setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
long_description=long_description,
long_description_content_type='text/markdown',
author=AUTHOR,
author_email=EMAIL,
python_requires=REQUIRES_PYTHON,
url=URL,
download_url=CURRENT_RELEASE,
keywords = ["k-mer", "kmer", "k-merdb", "kmerdb", "kdb"],
classifiers=[
"Development Status :: 1 - Planning",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Bio-Informatics",
"Topic :: Software Development :: Libraries :: Python Modules",
],
packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
package_dir={'kmerdb': 'kmerdb'},
package_data={'kmerdb': ['CITATION']},
# If your package is a single module, use this instead of 'packages':
#py_modules=['kmerdb'],
#scripts=['bin/kmerdb', 'bin/kmerdb_report.R'],
entry_points={
'console_scripts': ['kmerdb=kmerdb:cli'],
},
install_requires=REQUIRED,#['Cython==0.29.21', 'numpy==1.18.1'],
extras_require=EXTRAS,
include_package_data=True,
license='GPLv3+',
test_suite='test',
# tests_require=['mamba', 'expect'],
ext_modules=cythonize(extensions),
library_dirs=["."],
zip_safe=False,
)
我要在这里自我回答。该问题源于不正确指定的扩展。
Extension("kmerdb.distance", ["kmerdb/distance.pyx"], include_dirs=[np.get_include()])
我所要做的就是包含完全指定的子模块层次结构的模块名称。已修复!
我想问一个关于如何使用 Cython、setuptools 扩展等配置 setup.py
的问题。我正在尝试使用 Cython.Distutils
的 build_ext
对子模块进行 cythonize。但问题不在于 Cython.Distutils
的扩展模块(如果存在),因为它未加载。只有 build_ext
。所以我在列表中创建了一个 setuptools.extension
Extension,然后 cythonize Extension 对象的列表。列表中只有一个 Extension,如下所示。
Extension("distance", ["kmerdb/distance.pyx"], include_dirs=[np.get_include()])
我尝试了不同的安装方法,从 python setup.py install
到 pip install -e .
生成 wheel 文件并安装 wheel。我找不到任何有用的东西...
好的,所以我对这个过程知之甚少,这可能就是我挂断电话的原因,但我已经搜索了整个网站,但没有成功。就这样吧。
我运行下面的shell脚本在本地安装我的包,它工作正常。问题是安装没有将 .so
和 .py
文件移动到我要导出的 kmerdb
模块中。有什么建议么?谢谢
>python setup.py sdist bdist_wheel
>/bin/auditwheel repair --plat manylinux2014_x86_64 dist/kmerdb-*linux_x86_64.whl
>mv wheelhouse/* dist
>rm dist/*linux_x86_64.whl
>pip install dist/kmerdb-*-manylinux2014_x86_64.whl
>ls ~/.pyenv/versions/kdb/lib/python3.10/site-packages/kmerdb-0.6.5-py3.10-linux-x86_64.egg/
distance.cpython-310-x86_64-linux-gnu.so distance.py kmerdb ...
同样,文件 distance.cpython-310-x86_64-linux-gno.so
没有移入 kmerdb
模块,我的 Python 包,我正在尝试在本地安装并为 .whl
配置上传到 PyPI。
Python 3.10.1 (main, Jan 1 2022, 21:28:19) [GCC 11.1.0] on linux
Cython==0.29.26
setup.py
Extension("distance", ["kmerdb/distance.pyx"], include_dirs=[np.get_include()], define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],),
setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
long_description=long_description,
long_description_content_type='text/markdown',
author=AUTHOR,
author_email=EMAIL,
python_requires=REQUIRES_PYTHON,
url=URL,
download_url=CURRENT_RELEASE,
keywords = ["k-mer", "kmer", "k-merdb", "kmerdb", "kdb"],
classifiers=[
"Development Status :: 1 - Planning",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Bio-Informatics",
"Topic :: Software Development :: Libraries :: Python Modules",
],
packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
package_dir={'kmerdb': 'kmerdb'},
package_data={'kmerdb': ['CITATION']},
# If your package is a single module, use this instead of 'packages':
#py_modules=['kmerdb'],
#scripts=['bin/kmerdb', 'bin/kmerdb_report.R'],
entry_points={
'console_scripts': ['kmerdb=kmerdb:cli'],
},
install_requires=REQUIRED,#['Cython==0.29.21', 'numpy==1.18.1'],
extras_require=EXTRAS,
include_package_data=True,
license='GPLv3+',
test_suite='test',
# tests_require=['mamba', 'expect'],
ext_modules=cythonize(extensions),
library_dirs=["."],
zip_safe=False,
)
我要在这里自我回答。该问题源于不正确指定的扩展。
Extension("kmerdb.distance", ["kmerdb/distance.pyx"], include_dirs=[np.get_include()])
我所要做的就是包含完全指定的子模块层次结构的模块名称。已修复!