python - 使用 python setup.py egg_info 时安装 scikits.audiolab 时出错

标签 python pip scikits

我正在尝试使用 pip 工具安装 scikits.audiolab。 Pip 似乎从 scikits.audiolab 源目录中运行命令 python setup.py egg_info。当它这样做时,我得到这个错误:

Andrews-MacBook-Pro-2:scikits.audiolab-0.11.0 andrewhannigan$ pip install scikits.audiolab
Collecting scikits.audiolab
  Using cached scikits.audiolab-0.11.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/private/var/folders/xb/qwlsm44s1wxfr82kytrgjtl80000gn/T/pip-build-vSZaU8/scikits.audiolab/setup.py", line 32, in <module>
        from numpy.distutils.core import setup
    ImportError: No module named numpy.distutils.core

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/xb/qwlsm44s1wxfr82kytrgjtl80000gn/T/pip-build-vSZaU8/scikits.audiolab

问题很明显,它无法导入 numpy.distutils.core。查看 setup.py 脚本,此导入发生在早期(在下面代码片段的底部):

#! /usr/bin/env python
# Last Change: Fri Mar 27 05:00 PM 2009 J

# Copyright (C) 2006-2007 Cournapeau David <cournape@gmail.com>
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this library; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

# TODO:
#   - check how to handle cmd line build options with distutils and use
#   it in the building process

from os.path import join
import os
import sys

# The following is more or less random copy/paste from numpy.distutils ...
import setuptools

from distutils.errors import DistutilsError
from numpy.distutils.core import setup

奇怪的是,如果我只是通过 python setup.py 运行上面的 setup.py 脚本片段,我不会收到导入错误。 egg_info 命令行参数如何影响 setup.py 的运行方式,为什么它突然使 python 无法从 numpy.distutils.core 导入?

最佳答案

scikits.audiolabsetup.py 文件有问题。看看https://github.com/cournape/audiolab/blob/master/setup.py :

import os

# The following is more or less random copy/paste from numpy.distutils ...
import setuptools

from numpy.distutils.core import setup

它做的第一件事是从 numpy 导入。如果未安装 numpy,这肯定会失败并出现您分享的导入错误。

我怀疑在您失败的安装尝试和成功安装之间,您使用 pip install numpy 手动安装了 numpy。 egg_info 不太可能与它有任何关系。

下面是如何解决这个问题的演示,取自 scipy 项目的 setup.py:

def setup_package():
    ...
    build_requires = []
    try:
        import numpy
    except:
        build_requires = ['numpy']

    metadata = dict(
        ...
        setup_requires = build_requires,
        install_requires = build_requires,
    )

关于python - 使用 python setup.py egg_info 时安装 scikits.audiolab 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31212486/

相关文章:

Python:矩阵的非对角线元素为0

python - 损坏的 pip 安装仅适用于 sudo

python - 如何在 Windows 上启动 Spyder IDE

python - 谁能解释为什么 `skimage.measure.perimeter(img)` 返回这个结果?

svm - Scikit - SVM 的 3D 特征数组

python - 在 for 循环中附加一个列表?

python - 运算符的优先级 : > and ==

python - 如何在 dynamodb 中使用两个不同的凭据来拥有只读用户和所有访问用户?

python - pip 的 `--no-cache-dir` 有什么用?

machine-learning - python 机器学习 弃用警告