If you have nothing, begin with with putting get-pip.py in ~/bin/pip ???

Hi all,
I'm trying to answer the question: "On a modern GNU/Linux, if you have no 'pip' command, and you want to live in the modern Python Packaging world, how do you start?"
Hypothetically, let's say you're on the latest Python 2.7.
Also, I am presuming that you either don't have root on the system, or you don't want to run things with sudo.
One answer I've seen (and given...) is to download virtualenv.py by itself, and hope that it can create a virtualenv in e.g. ~/venv/base, and then always activate it.
You can see that advice given here: http://dubroy.com/blog/so-you-want-to-install-a-python-package/#the-better-w...
This advice is not contradicted here < http://www.virtualenv.org/en/latest/virtualenv.html#installation%3E although it seems like the advice basically is, "Make sure you have pip already, but if you don't, then we have no particular advice for you."
One alternative is to bootstrap via "get-pip.py", which happens (as far as I can tell) to operate properly as a ~/bin/pip. Then you can "pip install --user", and more.
However, get-pip.py http://pip.readthedocs.org/en/latest/installing.html seems to, if you run it with no arguments, want to write to /usr/bin/pip.
What I'm hoping exists is a variant of get-pip.py that I can suggest people put in ~/bin/pip (and tell them to fix their path to include $HOME/bin ), and then they can pip install --user to their heart's content. You could imagine this being called "heres-pip.py", rather than "get-pip.py", as in my imagination, running "heres-pip.py" would not be supposed to have side-effects like installing things unless you ask it to. You would just drop it into place.
Shell transcripts follow, to help you see what I'm seeing, in case I'm perhaps doing something wrong:
➜ /tmp python get-pip.py Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-1.5.4-py2.py3-none-any.wh... Downloading pip-1.5.4-py2.py3-none-any.whl (1.2MB): 1.2MB downloaded Installing collected packages: pip Found existing installation: pip 1.4.1 Uninstalling pip: Cleaning up... Exception: Traceback (most recent call last): File "/tmp/tmpL4ws00/pip.zip/pip/basecommand.py", line 122, in main status = self.run(options, args) File "/tmp/tmpL4ws00/pip.zip/pip/commands/install.py", line 279, in run requirement_set.install(install_options, global_options, root=options.root_path) File "/tmp/tmpL4ws00/pip.zip/pip/req.py", line 1376, in install requirement.uninstall(auto_confirm=True) File "/tmp/tmpL4ws00/pip.zip/pip/req.py", line 594, in uninstall paths_to_remove.remove(auto_confirm) File "/tmp/tmpL4ws00/pip.zip/pip/req.py", line 1781, in remove renames(path, new_path) File "/tmp/tmpL4ws00/pip.zip/pip/util.py", line 295, in renames shutil.move(old, new) File "/usr/lib/python2.7/shutil.py", line 303, in move os.unlink(src) OSError: [Errno 13] Permission denied: '/usr/bin/pip'
➜ /tmp python get-pip.py --user --upgrade mwparser Requirement already up-to-date: pip in /home/paulproteus/.local/lib/python2.7/site-packages Downloading/unpacking mwparser Downloading mwparser-0.1.tar.gz Running setup.py (path:/tmp/pip_build_paulproteus/mwparser/setup.py) egg_info for package mwparser
Installing collected packages: mwparser Running setup.py install for mwparser /home/paulproteus/.local/lib/python2.7/site-packages/mwparser.py:13: SyntaxWarning: assertion is always true, perhaps remove parentheses? assert('<' not in tag and '>' not in tag, "sample tag is 'ol'") /home/paulproteus/.local/lib/python2.7/site-packages/mwparser.py:14: SyntaxWarning: assertion is always true, perhaps remove parentheses? assert(len(start_marker) == 1, "This code assumes start_marker's length is 1")
Successfully installed mwparser Cleaning up...
So it seems that you can (ab?)use get-pip.py as a personal ~/bin/pip. You just have to know not to type "install". I'm guessing that "get-pip.py" is a "pip" binary with "install pip" pre-pended to sys.argv, so by passing more things, I happen to be able to cause it to do what I want. Either way, I'd like to know more about what is sensible to recommend as a bootstrapping process.
I presume that Mac OS users will have a similar issue as random GNU/Linux users who lack pip.
I will say, if get-pip.py wanted to do "pip install --user" rather than "pip install", then I'd be happy recommending it as-is.
(Other ideas welcome. I'm also semi-sure this is some kind of FAQ, but I don't see it in my reading of the distutils-sig list, so I thought I'd still ask it.)
Cheers,
Asheesh.
P.S. I am *so* tempted to add a no-op distribution called "install" to PyPI so that "pip install install" would look like it works.

This advice is not contradicted here < http://www.virtualenv.org/en/latest/virtualenv.html#installation%3E although it seems like the advice basically is,
"Make sure you have pip already, but if you don't, then we have no
particular advice for you."
that section actually offers 3 scenarios, not just pip - "To install globally with pip" - "To install globally from source" - "To use locally from source"
One alternative is to bootstrap via "get-pip.py"
if you haven't seen this, take a look: http://packaging.python.org/en/latest/tutorial.html
So it seems that you can (ab?)use get-pip.py as a personal ~/bin/pip. You
just have to know not to type "install".
get-pip has pip inside it, and it's calling "pip install -U pip [setuptools] sys.argv[1:]" (see here: https://raw.githubusercontent.com/pypa/pip/develop/contrib/get-pip.py)
the sys.argv[1:] is intended for passing arguments, but technically you can pass other packages and it will work. I don't think we should be recommending "get-pip.py" be used as "got-pip.py" in a talk. the "got-pip.py" idea has come up before, and it's something that should be discussed in full before recommending.
also, btw, it's currently under discussion to have pip's default behavior (and get-pip's) be --user installs. https://github.com/pypa/pip/issues/1668 https://groups.google.com/forum/#!topic/pypa-dev/r6qsAmJl9t0 https://github.com/pypa/python-packaging-user-guide/issues/43
participants (2)
-
Asheesh Laroia
-
Marcus Smith