0

I recently moved my os from debian7 to archlinux. On debian 7, the default python version is python2.7 but on archlinux the default is python3.4.

I once wrote a spider program using beautifulsoup4 on my debian7 but now I want to run this program on archlinux.

I use sudo pacman -S python-pipto install pip and then use sudo pip install beautifulsoup4. But this time this package goes into /usr/lib/python3.4/site-packages/.

I know I can download bs4 to my spider's directory and run it with python2, but I just want to know how do you install packages using pipsince you have 2 python version installed. And btw if I change the default python link to python2*, will it break my system?

Joey
  • 1,233
  • 3
  • 11
  • 18
  • download the get-pip.py https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py and run it with python2.7 then use pip2 to install packages for python2.7 – Padraic Cunningham Jul 13 '14 at 12:01
  • What the heck is a "spider program"? Why do you have a "spider directory" and what's the link with the python version you have installed? – Bakuriu Jul 13 '14 at 13:44
  • note that `pip install --user beautifulsoup4` is slightly less invasive than using `sudo`. also note that arch has `python-beautifulsoup4` and `python2-beautifulsoup4` packages already :) – Eevee Jul 13 '14 at 20:55

3 Answers3

0

Try python2-pip and pip2 or pip2.7.

In arch linux all of the python 3 packages have no version number and all the python 2 packages have a 2. The commands are the same way.

To select what version a script uses use the version number in the hashbang.

#! /usr/bin/env python2

or

#! /usr/bin/env python3

I'm not sure if debian has a python2 link but they can easily be created on systems where /usr/bin/python is python2.7.

sudo ln -s /usr/bin/python /usr/bin/python{2,2.7}
Kevin Cox
  • 3,080
  • 1
  • 32
  • 32
  • sudo ln -s /usr/bin/python /usr/bin/python{2,2.7} will this crash my system? since the default python links to python3.4. – Joey Jul 13 '14 at 12:06
  • That was meant to be run on debian where `python` is `python2.7`. Please never run that if `python` is not `python2.7` – Kevin Cox Jul 13 '14 at 12:15
0

"on archlinux the default is python3.4" - wow, this is ambitious.

The archlinux wiki on Python provides a lot of tips. You should install python2-pip to make sure that pip is installed for the right version.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • I've never heard of python2-pip before, I will try this. Is it that because the default python is python3, so the default pip downloads python3 packges? – Joey Jul 13 '14 at 12:01
0

Archlinux usually provides packages prefixed with python- for Python 3.x and python2- for Python 2.x. You can also use virtualenv to manage local Python environments, which means you can have a Python2 project and a Python3 project without conflicts between them.

bfontaine
  • 18,169
  • 13
  • 73
  • 107
  • Virtualenv is completely unnecessary for this probem as 2 and 3 can happily live side-by-side and Arch has them both packaged for you. – Kevin Cox Jul 13 '14 at 11:58
  • I know what you means, but even if I use virtualenvI have to use pip2 to install packages. I hate this version difference. – Joey Jul 13 '14 at 12:05