簡體   English   中英

當需要編譯 Cython 時,python setup.py install 的最佳替代品是什么?

[英]What is the best replacement for python setup.py install when Cython needs to be compiled?

使用最新版本的setuptools時, python setup.py install命令已被棄用(有關詳細信息,請參閱https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html )。

(venv) [jon@dev02 py38]$ python setup.py install
running install
/home/jon/.jenkins/workspace/Farm_revision_linux_py36/TOXENV/py38/venv/lib64/python3.8/site-
packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is 
deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
/home/jon/.jenkins/workspace/Farm_revision_linux_py36/TOXENV/py38/venv/lib64/python3.8/site-
packages/setuptools/command/easy_install.py:156: EasyInstallDeprecationWarning: easy_install 
command is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
running bdist_egg
running egg_info
... etc

建議直接pip install. 從源代碼安裝 package,但這不會編譯任何 Cython 代碼。 這樣做的最佳方法是什么?

Cython文檔仍然推薦使用setup.py ,我找不到更好的建議。 似乎開發人員安裝 ( pip install -e. ) 確實編譯了 Cython 文件,或者您可以在運行 pip install 后python setup.py build_ext --inplace pip install. . 這些選項都不是理想的,所以我想知道是否有建議的替代方案。

編輯:

package setup.py 文件包含這段代碼,它應該編譯 Cython 文件:

try:
    import numpy
    from Cython.Build import cythonize
    cython_files = ["farm/rasters/water_fill.pyx"]
    cython_def = cythonize(cython_files, annotate=True,
                           compiler_directives={'language_level': str(sys.version_info.major)})
    include_dirs = [numpy.get_include()]
except ImportError:
    cython_def = None
    include_dirs = None

使用python setup.py install時,farm/rasters 目錄包含以下文件:

water_fill.c
water_fill.cpython-38-x86_64-linux-gnu.so
water_fill.html
water_fill.pyx

安裝時使用pip install. ,該目錄不包含 .so 文件,當我們嘗試運行 water_fill 測試時,我們得到這樣的錯誤

________________________________ TestFlowDown1D.test_distribute_1d_trough_partial_3 _________________________________
farm/rasters/tests/test_flood_enhance.py:241: in test_distribute_1d_trough_partial_3
    actual_arr = water_fill.water_fill_1d(arr, additional_value)
E   AttributeError: 'NoneType' object has no attribute 'water_fill_1d'

我相信如果保留 setup.py 但添加 pyproject.toml,警告應該消失 go。 https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html中描述了如何執行此操作。

這是他們給出的示例 pyproject.toml 文件:

[build-system]
requires = ["setuptools", "wheel", "Cython"]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM