0

I have installed bottle on my Ubuntu Linux server using

sudo pip install bottle

and it is installed to: /usr/local/lib/python2.7/dist-packages

But I also have Python 3.2 installed on my system, and I want to access bottle from Python 3.2. Python 3.2 does not seem to recognise that bottle is installed.

What am I doing wrong?

Helgi
  • 5,428
  • 1
  • 31
  • 48
Duke Dougal
  • 24,359
  • 31
  • 91
  • 123

4 Answers4

3

You'd have to separately install it for Python 3.2 (with e.g. sudo pip-3.2 install bottle).

It's currently in python2.7/dist-packages, meaning that only 2.7 is going to load it. You could try to add that to your PYTHONPATH or similar, but that will very rarely work between Python 2 and 3 because the source files aren't quite compatible. (Any C extensions are also certainly not going to work, though bottle doesn't have any of those.)

Unfortunately, although that command works, it looks like the version of bottle in pypi isn't Python 3-compatible even when installed through pip-3.2:

In [1]: import bottle
  File "/Library/Frameworks/Python.framework/Versions/3.2/bin/bottle.py", line 373
    except re.error, e:
                   ^
SyntaxError: invalid syntax

The homepage claims that it works with 3.x, but I got that error installing with both pip and easy_install. The latest development version, which is just a single file linked from the homepage, seems to work, though.

Danica
  • 28,423
  • 6
  • 90
  • 122
  • Where can I get pip-3.2 from? – Duke Dougal May 27 '12 at 08:42
  • 1
    @DukeDougal: In the meantime, dropping the `bottle.py` file (the development version of it) into your app's directory should do. The author of Bottle has this way of deployment in mind when he decided to distribute the library in a single file. – Helgi May 27 '12 at 11:55
  • @Helgi thanks yes this is what I'm doing at the moment. I'm still confused - the two people who have answered here say I should be using pip-3.2 but I can't see any pip-3.2 for download nor any mention of it anywhere. – Duke Dougal May 27 '12 at 13:30
  • 1
    @DukeDougal Pop generally installs a versioned number of itself as well as the main pip script. Depending on how you installed 3.2, you may need to get distribute (to get easy_install-3.2) and then `easy_install-3.2 pip`. – Danica May 27 '12 at 14:05
  • 1
    The 0.10 release needs 2to3 to work. pip-2.3 does this automatically, but copying the file around won't work without 2to3. The development version works with both versions from a single source (no 2to3 needed) and can be copied directly. – defnull May 28 '12 at 20:15
  • Gak. This all sounds too hard - all I want is to install stuff to use with Python 3.2. Is there no easier way than futzing around with pip like this? – Duke Dougal May 28 '12 at 23:50
0

You are not doing anything wrong. Pip uses the /usr/bin/python by default and only installs there. Unless you want to setup virtualenv-s, you probably best copy the current pip to pip3.2 and edit that to call python 3.2:

sudo -s -H
p=$(which pip)
cat $p | sed "1s|/usr/bin/python|$(which python3.2)|" > $p"3.2"
chmod 755 $p"3.2"
exit

You now have a pip3.2 that will install bottle so python3.2 can use it. If you get an error running pip3.2 about not finding pkg_resources look at No module named pkg_resources

Community
  • 1
  • 1
Anthon
  • 69,918
  • 32
  • 186
  • 246
0

I'll answer this myself. Turns out the latest release version of pip does not include pip-3.2. You need to download the development version and use that, which includes pip-3.2.

Duke Dougal
  • 24,359
  • 31
  • 91
  • 123
0

Just download it manually from offsite. It is just one file. Place it into the lib/site-packages folder and give the file proper rights.