Python - Is there any way to get pip without setuptools? - python

Seems kinda weird that they'd require a package manager to install a package manager. I'm on Windows BTW.

Pip does require setuptools. Pip is really just a wrapper around setuptools to provide a better installer than easy_install and some nicer installation behaviors, plus uninstall, requirements files, etc. Even if you somehow got pip installed without setuptools it still won't run without it.

You can use Distribute instead of setuptools: it installs a package called setuptools (it's a fork of the latter). You can install Distribute by downloading and running distribute_setup.py.
Update: As Gringo Suave says, the above is obsolete now - distribute and setuptools have now merged, and the merged project is called setuptools.

You can download setuptools package as Windows installer from pypi/setuptools and then install pip or easy_install

Solution for Windows Users
If you installed ActivePython on Windows, then you have pip by default, as well as PyPM (ActiveState's package manager). The following excerpt is from What's included in ActivePython 2.7:
Additional Packages
PyPM: Python Package Manager to download and install binary packages. Also included: virtualenv, Distribute, pip, SQLAlchemy.
Solution for OS X Users
Not sure if setuptools is required when installing pip using homebrew. You might try that.
To install homebrew:
ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)"
Then to install pip:
brew install pip

Sure, just grab the source from http://pypi.python.org/pypi/pip/0.8.2#downloads
unpack it, cd into it, and run python setup.py install

Related

Should I manually install all my system wide packages after upgrading to Python 3?

I have some systemwide packages I've installed and I'm unclear whether I'm supposed to install another copy of them all for Python3 or if there is some way to 'point' Python3 at them. I'm on a Mac.
I still have Python 2.7.9 which has all the packages (most installed with either brew or pip and maybe one or two manually like pyqt). Do I basically have to redo the installation process for every single package again? Or is there some way to simply have Python3 'inherit' everything I've installed so far under 2.7.9?
Also, from what I understand, to install under Python3 with pip I would use pip3 install, is that correct? How would I do the same with ones installed with Homebrew? Is there a brew3 command? Or does Homebrew install to all versions of Python?
You do need to reinstall, but I would step away from systemwide installs in general and start using project-specific package installation.
Use pyenv for version switching and virtualenv for isolated environments.
pyvenv works rather well.
Install Python 3
python -m venv "my_virtual_env"
my_virtual_env\Scripts\activate
pip search lib
pip install ...
You will have to look up what the activate command is for osx. pip is the standard package manager now. You can search, install, and uninstall with pip. Pip is also moving towards wheels when installing packages. You probably don't have to worry about wheels too much though.

How to `pip install` a package that has non-Python dependencies?

Many python packages have build dependencies on non-Python packages. I'm specifically thinking of lxml and cffi, but this dilemma applies to a lot of packages on PyPI. Both of these packages have unadvertised build dependencies on non-Python packages like libxml2-dev, libxslt-dev, zlib1g-dev, and libffi-dev. The websites for lxml and cffi declare some of these dependencies, but it appears that there is no way to do figure this out from a command line.
As a result, there are hundreds of questions on SO that take this general form:
pip install foo fails with an error: "fatal error: bar.h: No such file or directory". How do I fix it?
Is this a misuse of pip or is this how it is intended to work? Is there a sane way to know what build dependencies to install before running pip? My current approach is:
I want to install a package called foo.
pip install foo
foo has a dependency on a Python package bar.
If bar build fails, then look at error message and guess/google what non-Python dependency I need to install.
sudo apt-get install libbaz-dev
sudo pip install bar
Repeat until bar succeeds.
sudo pip uninstall foo
Repeat entire process until no error messages.
Step #4 is particularly annoying. Apparently pip (version 1.5.4) installs the requested package first, before any dependencies. So if any dependencies fail, you can't just ask pip to install it again, because it thinks its already installed. There's also no option to install just the dependencies, so you must uninstall the package and then reinstall it.
Is there some more intelligent process for using pip?
This is actually a comment about the answer suggesting using apt-get but I don't have enough reputation points to leave one.
If you use virtualenv a lot, then installing the python-packages through apt-get can become a pain, as you can get mysterious errors when the python packages installed system-wide and the python packages installed in your virtualenv try to interact with each other. One thing that I have found that does help is to use the build-dep feature. To build the matplotlib dependencies, for example:
sudo apt-get build-dep python-matplotlib
And then activate your virtual environment and do pip install matplotlib. It will still go through the build process but many of the dependencies will be taken care of for you.
This is sort what the cran repositories suggest when installing R packages in ubuntu.
For most popular packages, There is a workaround for recent ubuntu systems. For example, I want to install matplotlib. When you order pip install matplotlib, it usually fails because of a missing dependency.
You can use apt-get install python-matplotlib instead. For python3, you can use apt-get install python3-matplotlib

Why would a python framework installation guide advise the use of easy_install for some required packages and pip for others?

After a failed attempt at a "streamlined" install of the SimpleCV framework superpack for Windows. I'm now working through a manual installation guide (which I'm OK with as I have more control over the installation and might finally learn about installing Python Packages properly in Windows!)
Rather than just blindly follow the guide I'm trying to understand each step, so I'm confused by this..
easy_install pyreadline
easy_install PIL
easy_install cython
easy_install pip
pip install ipython
pip install https://github.com/ingenuitas/SimpleCV/zipball/1.3
Why not easy_install pip as soon as possible then pip the other packages?..
easy_install pip {{{I intend to research and probably use get-pip.py here}}}
pip install pyreadline
pip install PIL
pip install cython
pip install ipython
pip install https://github.com/ingenuitas/SimpleCV/zipball/1.3
Is there a pitfall doing it this way? (My limited understanding is that it's always preferable to use pip rather than easy_install.)
I know this question relates directly to SimpleCV but I want to learn the correct approach for when I'm installing package collections in the future without the benefit of a guide.
pip fetches the source code of the packages you're trying to install and compiles them. So if you don't have a compiler installed and configured it will fail to do so for packages which contain extensions written in C, which in this case applies to pyreadline, PIL and cython.
easy_install uses the precompiled packages from pypi (at least for windows if they're available), which means you don't need to compile everything yourself.
For pure python packages it's no problem using pip instead of easy_install, and if you have a compiler and the neccessary build dependencies installed it should also work.
I believe the answer is that pip does not currently support the installation of binary distributions, i.e. Python packages that include pre-compiled C extension modules. easy_install does.
BTW, there is work afoot to provide replacements for pip (and easy_install) that will fully support binary distributions on all platforms. See here for an overview.

How to Uninstall setuptools python

Hi recently i installed setup tools module and google app engine gives me errors . Is there a way to uninstall setuptool? can any one tell me step by step because i tried hard
The answer depends on how it was installed.
If it was installed using the ubuntu (debian) package manager, try:
sudo apt-get remove --purge python-setuptools
[updated]
If you installed manually, probably the setuptools final location will be something like (adjust for your environment/python version):
/usr/local/lib/python2.6/dist-packages
Just delete the setuptools stuff there.
Lame, I know, but it is your burden for not using the excellent package manager provided by ubuntu: stick to dpkg unless you need bleeding edge stuff. For other python modules installed by setuptools, it provides no "uninstall" feature (but pip does, that is why there is a lot of enthusiasm around virtualenv, pip and yolk).
[2017 update]
It is 2017 and installing Python modules changed a bit:
pip is now the preferred installer program. Starting with Python 3.4, it is included by default with the Python binary installers.
venv is the standard tool for creating virtual environments (semi-isolated Python environments that allow packages to be installed for use by a particular application, rather than being installed system wide), and has been part of Python since Python 3.3. Starting with Python 3.4, it defaults to installing pip into all created virtual environments.
virtualenv is a third party alternative (and predecessor) to venv and if not official it is still very popular because it allows virtual environments to be used on versions of Python prior to 3.4, which either don’t provide venv at all, or aren’t able to automatically install pip into created environments.
easy_install pip
pip uninstall pip setuptools
(pip and setuptools both use the same package formats, but pip has uninstall support. kinda hilarious that installing something is the easiest way to uninstall.)
I was having trouble with the method below because my pip wasn't up to date.
easy_install pip
pip uninstall pip setuptools
After upgrading pip like this:
sudo -H pip install --upgrade pip
I was able to successfully uninstall setuptools like so:
pip uninstall setuptools

Installing Python egg dependencies without apt-get

I've got a Python module which is distributed on PyPI, and therefore installable using easy_install. It depends on lxml, which in turn depends on libxslt1-dev. I'm unable to install libxslt1-dev with easy_install, so it doesn't work to put it in install_requires. Is there any way I can get setuptools to install it instead of resorting to apt-get?
setuptools can only install Python packages that in the package index you are using, either the default index of the one you specify with easy_install -i http://myindex.site/index.
Any non-Python dependencies have to be installed using the standard installation package for the platform (apt-get on Debian based Linux distros). libxml2 and libxslt fall into this category so you should install these in the standard way.
It's better use apt-get to install lxml (or the python packages that has c extensions) and then pull pure python package from pypi. Also I generally try to avoid using easy_install for top level install, I rather create a virtual env using virtualenv and then use easy_install created by virtualenv to keep my setups clean.
This strategy is working successfully for me for couple of production environments.

Categories