Difference between 'python setup.py install' and 'pip install'
On the surface, both do the same thing: doing either python setup.py install
or pip install <PACKAGE-NAME>
will install your python package for you, with a minimum amount of fuss.
However, using pip offers some additional advantages that make it much nicer to use.
- pip will automatically download all dependencies for a package for you. In contrast, if you use
setup.py
, you often have to manually search out and download dependencies, which is tedious and can become frustrating. - pip keeps track of various metadata that lets you easily uninstall and update packages with a single command:
pip uninstall <PACKAGE-NAME>
andpip install --upgrade <PACKAGE-NAME>
. In contrast, if you install a package usingsetup.py
, you have to manually delete and maintain a package by hand if you want to get rid of it, which could be potentially error-prone. - You no longer have to manually download your files. If you use
setup.py
, you have to visit the library's website, figure out where to download it, extract the file, runsetup.py
... In contrast, pip will automatically search the Python Package Index (PyPi) to see if the package exists there, and will automatically download, extract, and install the package for you. With a few exceptions, almost every single genuinely useful Python library can be found on PyPi. - pip will let you easily install wheels, which is the new standard of Python distribution. More info about wheels.
- pip offers additional benefits that integrate well with using
virtualenv
, which is a program that lets you run multiple projects that require conflicting libraries and Python versions on your computer. More info. - pip is bundled by default with Python as of Python 2.7.9 on the Python 2.x series, and as of Python 3.4.0 on the Python 3.x series, making it even easier to use.
python setup.py install
.If you're using an older version of Python, can't upgrade, and don't have pip installed, you can find more information about installing pip at the following links:
- Official instructions on installing pip for all operating systems
- Instructions on installing pip on Windows (including solutions to common problems)
- Instructions on installing pip for Mac OX
pip install <PACKAGE-NAME>
. That said, if you're interested in learning more about the details of what exactly you can do with pip, see:- Quickstart guide
- Official documentation.
If you'd like to learn more about using pip and virtualenv together, see:
- Why you should be using pip and virtualenv
- A non-magical introduction to Pip and Virtualenv for Python beginners
- Virtual Environments
Difference between pip3 and `python3 setup.py install` regarding cmdclass argument
pip calls your setup.py but it redirects stdout/stderr. To test setup.py under pip write to a file in a fixed location:
class ActionOnInstall(install):
def run(self):
print("Call install.run(self) works!", file=open('/tmp/debug.log', 'w'))
install.run(self)
Look into /tmp/debug.log after pip install .
What's the difference between pip install and python -m 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.
Here's some more concrete "proof", beyond just trusting my word and the bug report I linked :)
If you take a look at the pip
executable script, it's just doing this:
from pkg_resources import load_entry_point
<snip>
load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
It's calling load_entry_point
, which returns a function, and then executing that function. The entry point it's using is called 'console_scripts'
. If you look at the entry_points.txt file for pip
(/usr/lib/python2.7/dist-packages/pip-1.5.4.egg-info/entry_points.txt on my Ubuntu machine), you'll see this:[console_scripts]
pip = pip:main
pip2.7 = pip:main
pip2 = pip:main
So the entry point returned is the main
function in the pip
module.When you run python -m pip
, you're executing the __main__.py
script inside the pip
package. That looks like this:
import sys
from .runner import run
if __name__ == '__main__':
exit = run()
if exit:
sys.exit(exit)
And the runner.run
function looks like this:def run():
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
## FIXME: this is kind of crude; if we could create a fake pip
## module, then exec into it and update pip.__path__ properly, we
## wouldn't have to update sys.path:
sys.path.insert(0, base)
import pip
return pip.main()
As you can see, it's just calling the pip.main
function, too. So both commands end up calling the same main
function in pip/__init__.py
. pip install --editable ./ vs python setup.py develop
Try to avoid calling setup.py
directly, it will not properly tell pip that you've installed your package.
With pip install -e
:
For local projects, the “SomeProject.egg-info” directory is createdMore: docs
relative to the project path. This is one advantage over just usingsetup.py develop
, which creates the “egg-info” directly relative the
current working directory.
Also read the setuptools' docs.
Difference between setup.py install and setup.py develop
develop
creates an .egg-link
file in the site-packages
directory, which points back to the location of the project files. The same path is also added to the easy-install.pth
file in the same location. Uninstalling with setup.py develop -u
removes that link file again.
Do note that any install_requires
dependencies not yet present are also installed, as regular eggs (they are easy_install
-ed). Those dependencies are not uninstalled when uninstalling the development egg.
Related Topics
Does Conda Replace the Need for Virtualenv
How to Use the Optional Type Hint
Preventing Python Code from Importing Certain Modules
Python Socket Receive - Incoming Packets Always Have a Different Size
Python Wildcard Search in String
How to Align Gridlines for Two Y-Axis Scales Using Matplotlib
Find All Upper, Lower and Mixed Case Combinations of a String
Weighted Standard Deviation in Numpy
Split Dataframe into Relatively Even Chunks According to Length
Numpy 1.21.2 May Not Yet Support Python 3.10
How to Combine Multiple Rows into a Single Row with Pandas
Hide Chromedriver Console in Python
How to Convert a Python List into a C Array by Using Ctypes
How to Get Tweets Older Than a Week (Using Tweepy or Other Python Libraries)
Appending to the Same List from Different Processes Using Multiprocessing