如何使用setuptools

时间:2016-01-28 07:46:33

标签: python numpy scipy setuptools

我正在开发一个python 3.4模块,它有scipy和numpy作为依赖项。所以我在install_requires下的setup.py中声明了它们。

以下是我的setup.py

的最小运行示例
from setuptools import setup

setup(
        name='MyModule',
        version='1.0.5',
        author='Alexander Mueller',
        packages=[],
        scripts=[],
        license='LICENSE.txt',
        description='Stuff',
        install_requires=[
            "pandas == 0.15.2",
            "scikit-learn==0.17",
            "seaborn == 0.5.1",
            "scipy == 0.17.0",
            "numpy==1.10.4"
        ]
)

运行 python setup.py install 时会发生以下异常。

但是,当我使用pip install按顺序安装所有这些软件包时,根本不会发生任何错误。可能是easy_install问题吗?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "setup.py", line 16, in <module>
    "numpy==1.10.4"
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/command/install.py", line 117, in do_egg_install
    cmd.run()
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 380, in run
    self.easy_install(spec, not self.no_deps)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 610, in easy_install
    return self.install_item(None, spec, tmpdir, deps, True)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 661, in install_item
    self.process_distribution(spec, dist, deps)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 709, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/pkg_resources/__init__.py", line 830, in resolve
    dist = best[req.key] = env.best_match(req, ws, installer)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/pkg_resources/__init__.py", line 1075, in best_match
    return self.obtain(req, installer)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/pkg_resources/__init__.py", line 1087, in obtain
    return installer(requirement)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 629, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 659, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 842, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 1070, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 1056, in run_setup
    run_setup(setup_script, args)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/sandbox.py", line 240, in run_setup
    raise
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/sandbox.py", line 193, in setup_context
    yield
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/contextlib.py", line 77, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/sandbox.py", line 164, in save_modules
    saved_exc.resume()
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/sandbox.py", line 139, in resume
    compat.reraise(type, exc, self._tb)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/compat.py", line 65, in reraise
    raise value.with_traceback(tb)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/sandbox.py", line 152, in save_modules
    yield saved
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/sandbox.py", line 193, in setup_context
    yield
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/sandbox.py", line 237, in run_setup
    DirectorySandbox(setup_dir).run(runner)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/sandbox.py", line 267, in run
    return func()
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/sandbox.py", line 236, in runner
    _execfile(setup_script, ns)
  File "/Users/alexandermueller/.virtualenvs/fpm_test3/lib/python3.4/site-packages/setuptools/sandbox.py", line 46, in _execfile
    exec(code, globals, locals)
  File "/var/folders/b0/_y4bfk6x4bldrmtycxhmbtrm0000gn/T/easy_install-drrk1iwn/scipy-0.17.0/setup.py", line 265, in <module>
  File "/var/folders/b0/_y4bfk6x4bldrmtycxhmbtrm0000gn/T/easy_install-drrk1iwn/scipy-0.17.0/setup.py", line 253, in setup_package
ImportError: No module named 'numpy'

提前谢谢你们。

1 个答案:

答案 0 :(得分:-2)

订单似乎在这里很重要,这个订单安装了所需的包

install_requires=[
            "numpy == 1.10.4",
            "pandas == 0.15.2",
            "seaborn == 0.5.1",
            "scipy == 0.17.0",
            "scikit-learn == 0.17"
        ]

使用pip3 1.5.4,xubuntu 14.04

进行测试