本文介绍了在使用numpy.distutils.core.setup之前安装numpy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用numpy.distutils设置具有frotran模块的程序包(mypackage).问题是,如果我在没有numpy的环境上执行pip install mypackage,则会收到以下错误:

I am using numpy.distutils to setup a package (mypackage) that has a frotran module. The problem is that if I do pip install mypackage on an environment that does not have numpy, I get the following error:

简单的解决方案是要求用户(如果可以的话)在安装软件包之前要求pip install numpy,但是我认为这不是一个非常优雅的解决方案.

The easy solution is to ask users (if I manage to have any) to pip install numpy before they install my package, but I do not think this is a very elegant solution.

我想到了在导入numpy之前仅用setup_requires=['numpy']调用setuptools.setup的想法,它似乎运行良好.这是我的setup.py:

I came up with the idea of calling setuptools.setup with only setup_requires=['numpy'] before I import numpy and it seems to work well. This is my setup.py:

import setuptools

setuptools.setup(
    setup_requires=[
        'numpy'
    ],)

from numpy.distutils.core import setup, Extension

mod = Extension(name='mypackage.amodule', sources=['source/a.f90'])

setup(name='mypackage',
      packages=['mypackage'],
      ext_modules=[mod],)

老实说,我不完全理解调用空setup()的含义(无名称,无程序包). 这是一个好的解决方案吗?这是一种不好的做法吗?

I honestly don't fully understand what it implies to call an empty setup() (no name, no package). Is this a good solution? Is this somehow a bad practice?

推荐答案

这是一个常见问题.如何安装 build-time 依赖项?您可能要使用pyproject.toml文件并利用build-system功能.参见 PEP517 .还有一个例子:

It is a common issue. How to install a build-time dependency? You might want to use a pyproject.toml file and take advantage of the build-system feature. See PEP517. And an example here:

[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools", "numpy"]

使用 pep517工具构建发行版( sdist wheel ).

这篇关于在使用numpy.distutils.core.setup之前安装numpy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 13:18
查看更多