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?
The most common command is pip freeze > requirements. txt , which records an environment's current package list into requirements. txt. If you want to install the dependencies in a virtual environment, create and activate that environment first, then use the Install from requirements.
The -e flag makes it an “editable” install, leaving the source code in place and allowing you to modify it if desired. (Otherwise, by default, pip would move the python code to some site-packages directory and delete everything else.)
A Beginner's Guide to Pip A requirements file is a list of all of a project's dependencies. This includes the dependencies needed by the dependencies. It also contains the specific version of each dependency, specified with a double equals sign ( == ). pip freeze will list the current projects dependencies to stdout .
It dumps all the libraries installed in your project including dependencies and sub-dependencies in the requirements. txt file. It still misses out on the libraries that are not installed using pip. It doesn't remove a library automatically if it is not being used in a project.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With