How do I make Pip respect requirements?

邮差的信 提交于 2019-12-30 08:09:26

问题


If I create a setup.py using requires, Pip doesn't install my dependencies.

Here's my setup.py:

from distutils.core import setup

setup(name='my_project',
      description="Just a test project",
      version="1.0",
      py_modules=['sample'],
      requires=['requests'])

I wrote a simple sample.py:

import requests

def get_example():
    return requests.get("http://www.example.com")

I then try to install it:

$ pip install -e .                                                                                    [15:39:10]
Obtaining file:///tmp/example_pip
  Running setup.py egg_info for package from file:///tmp/example_pip

Installing collected packages: my-project
  Running setup.py develop for my-project

    Creating /tmp/example_pip/my_venv/lib/python2.7/site-packages/my-project.egg-link (link to .)
    Adding my-project 1.0 to easy-install.pth file

    Installed /tmp/example_pip

Note that requests, my dependency isn't installed. If I now try to use my test project:

$ python                                                                                              [15:35:40]
>>> import sample
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/example_pip/sample.py", line 1, in <module>
    import requests
ImportError: No module named requests

What am I doing wrong?


回答1:


The correct spelling is install_requires, not requires; this does require that you use setuptools, not distutils:

from setuptools import setup

setup(name='my_project',
      description="Just a test project",
      version="1.0",
      py_modules=['sample'],
      install_requires=['requests'])

I can recommend the Python Packaging User Guide for the nitty gritty details.



来源:https://stackoverflow.com/questions/12372336/how-do-i-make-pip-respect-requirements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!