我正在尝试使用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
导入?
答案 0 :(得分:3)
scikits.audiolab
setup.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
{<1}}中演示如何解决此问题的演示:
def setup_package():
...
build_requires = []
try:
import numpy
except:
build_requires = ['numpy']
metadata = dict(
...
setup_requires = build_requires,
install_requires = build_requires,
)