[英]What is the best replacement for python setup.py install when Cython needs to be compiled?
With the latest version of setuptools , the python setup.py install
command is being deprecated (see https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for more info).使用最新版本的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
It is suggested that you can just pip install.
建议直接
pip install.
to install a package from source, but this does not compile any Cython code.从源代码安装 package,但这不会编译任何 Cython 代码。 What is the best method for doing this?
这样做的最佳方法是什么?
The Cython docs are still recommending use of setup.py
and I can't find any better suggestions. Cython文档仍然推荐使用
setup.py
,我找不到更好的建议。 It appears that a developer install ( pip install -e.
) does compile the Cython files, or you can python setup.py build_ext --inplace
after running pip install.
似乎开发人员安装 (
pip install -e.
) 确实编译了 Cython 文件,或者您可以在运行 pip install 后python setup.py build_ext --inplace
pip install.
. . Neither of these options are ideal, so I would like to know if there is a suggested alternative.
这些选项都不是理想的,所以我想知道是否有建议的替代方案。
EDIT:编辑:
The package setup.py file contains this code, which should compile the Cython files: 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
When installing with python setup.py install
, the farm/rasters directory contains the following files:使用
python setup.py install
时,farm/rasters 目录包含以下文件:
water_fill.c
water_fill.cpython-38-x86_64-linux-gnu.so
water_fill.html
water_fill.pyx
When installing with pip install.
安装时使用
pip install.
, the directory does not contain the.so file and when we try and run water_fill tests, we get errors like this ,该目录不包含 .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'
I believe the warning should go away if you keep the setup.py but add a pyproject.toml.我相信如果保留 setup.py 但添加 pyproject.toml,警告应该消失 go。 How to do this is described in https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html .
https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html中描述了如何执行此操作。
Here is the example pyproject.toml file they give:这是他们给出的示例 pyproject.toml 文件:
[build-system]
requires = ["setuptools", "wheel", "Cython"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.