I'm following a Flask tutorial that has me using virtualenv
, and with it I built an app directory tree that looks like this:
app/
|__app/
|__app.egg-inf/
|__setup.py
|__venv/
Inside my venv
the tutorial tells me to run pip install -e .
which appears to be using my setup.py
to install dependencies and my application.
Why does the tutorial have me running pip install -e .
? Why not python setup.py install
? What are the differences?
(FWIW, export FLASK_APP=app; flask run
works fine after pip install -e .
but doesn't work after a python setup.py install
)
They do exactly the same thing. In fact, the docs for distributing Python modules were just updated to suggest using python -m pip instead of the pip executable, because it's easier to tell which version of python is going to be used to actually run pip that way.
pip is a package manager, which can install, upgrade, list and uninstall packages, like familiar package managers including: dpkg, apt, yum, urpmi, ports etc. Under the hood, it will run python setup.py install , but with specific options to control how and where things end up installed.
As a first step, pip needs to get metadata about a package (name, version, dependencies, and more). It collects this by calling setup.py egg_info . The egg_info command generates the metadata for the package, which pip can then consume and proceed to gather all the dependencies of the package.
Traditionally, your default Python was installed system-wide (also known as a global install), typically using an installer. But this meant that all Python dependencies would be installed centrally in the site-packages directory.
First, the commands you mention are not equivalent, specifically python setup.py install
does not give you an editable installation. The pip <-> python setup.py
equivalents are:
Editable pip setup.py
yes pip install -e . python setup.py develop
no pip install . python setup.py install
With that said, using pip
is in general recommended for a range of reasons:
In your case, I highly suspect that your package has a dependency which is automatically installed if you use pip, but not if you use python setup.py install
.
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