I'm new to python and was curious if python had something like an npm install
that would pip install the required packages for a script I have. I've looked into the setup.py
readme and it looks like its mostly geared to creating a tarball to send to pip, which isn't what I want.
I'd like to be able to check out the source code and then just run it. As it stands when I ask my coworkers to use the script they run into import failures and have to manually pip install things which is a poor experience.
My setup.py file is
#!/usr/bin/env python
from distutils.core import setup
setup(name='Add-Webhook',
version='1.0',
description='Adds webhooks to git repos',
author='devshorts',
packages=['requests'],
)
And when I run it it
$ python setup.py install
running install
running build
running build_py
error: package directory 'requests' does not exist
I have a small script that sits next to the setup.py that uses the requests
package and I'd like for it to be installed on 'install'
$ ls
total 40
-rw-r--r-- 1 akropp JOMAX\Domain Users 1039 Feb 24 09:51 README.md
-rwxr-xr-x 1 akropp JOMAX\Domain Users 4489 Feb 27 17:01 add-webhook.py
-rw-r--r-- 1 akropp JOMAX\Domain Users 391 Feb 23 14:24 github.iml
-rw-r--r-- 1 akropp JOMAX\Domain Users 213 Apr 8 15:06 setup.py
Create requirements.txt
file in your project's root directory, and add necessary Python packages with the versions you need.
Then just run $pip install -r requirements.txt
to install everything that you have specified in requirements.txt
file.
Not sure if this is what you need, but this is something better than running $pip install <package name>
for several times.
You have misunderstood the parameters for setup
. The packages
parameter is for specifying the packages that you are providing, not the dependencies of those packages.
Per the documentation:
Dependencies on other Python modules and packages can be specified by supplying the requires keyword argument to
setup()
. The value must be a list of strings. Each string specifies a package that is required, and optionally what versions are sufficient.
You could also consider using setuptools
instead of distutils
(switch to from setuptools import setup
) and specifying install_requires
(see the docs on dependency declarations) - see e.g. Differences between distribute, distutils, setuptools and distutils2?
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