Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup in virtualenv: `pip install -e .` vs `python setup.py install`

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)

like image 753
Juicy Avatar asked Jul 31 '17 23:07

Juicy


People also ask

What is the difference between pip install and Python pip 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.

Does pip install run setup py?

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.

Does pip need setup py?

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.

What is pip install Virtualenv?

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.


1 Answers

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:

  • Dependencies are automatically installed
  • There is an easy way to uninstall

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.

like image 93
Jonas Adler Avatar answered Sep 29 '22 02:09

Jonas Adler