Asked By – user2125465
I have an external package I want to install into my python virtualenv from a tar file.
What is the best way to install the package?
I’ve discovered 2 ways that can do it:
- Extract the tar file, then run
python setup.py installinside of the extracted directory.
pip install packagename.tar.gzfrom example # 7 in https://pip.pypa.io/en/stable/reference/pip_install/#examples
Is if there is any difference doing them in these 2 ways.
Now we will see solution for issue: 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>and
pip install --upgrade <PACKAGE-NAME>. In contrast, if you install a package using
setup.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, run
setup.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.
So basically, use pip. It only offers improvements over using
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, by itself, doesn’t really require a tutorial. 90% of the time, the only command you really need is
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:
It is also commonly recommended that you use pip and virtualenv together. If you’re a beginner to Python, I personally think it’d be fine to start of with just using pip and install packages globally, but eventually I do think you should transition to using virtualenv as you tackle more serious projects.
If you’d like to learn more about using pip and virtualenv together, see:
This question is answered By – Michael0x2a
This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0