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

Asheesh Laroia lists at asheesh.org
Mon Apr 7 06:32:40 CEST 2014


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-way


This advice is not contradicted here <
http://www.virtualenv.org/en/latest/virtualenv.html#installation> 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.whl#md5=f20bc8f31e322375ce06b26d73ce7b4f
  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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20140406/9350804d/attachment.html>


More information about the Distutils-SIG mailing list