2014-10-22 6 views
12

Ich habe diesen Code (wie in BS4 documentaion geschrieben):Ubuntu - Wie installiert man ein Python-Modul (BeautifulSoup) auf Python 3.3 anstelle von Python 2.7?

from bs4 import BeautifulSoup 

Als ich das Drehbuch (mit python3) laufen bekomme ich den Fehler:

ImportError: No module named 'bs4' 

So installiert BeatifulSoup von:

sudo pip install BeatifulSoup4 

Aber wenn ich versuche, das Skript erneut auszuführen, bekomme ich den gleichen Fehler. Tat BS4 ist in installiert:

BeautifulSoup4 in /usr/local/lib/python2.7/dist-packages 

Aber ich möchte installieren und verwenden Sie es mit python3.3 (wie es andere Modul sind, die nicht mit python2.7 arbeiten).

Ich habe versucht, mit:

virtualenv --python=/usr/bin/python2.7 /usr/bin/python3.3 

und dann wieder installieren BS4, aber nichts gelöst.

Irgendwelche Hinweise? Vielen Dank im Voraus

+0

http://stackoverflow.com/questions/6587507/how-to-install-pip-with-python-3 – greschd

+0

http://stackoverflow.com/questions/10919569/ how-to-pip-install-zu-spezifische-version-of-python –

Antwort

27

Ubuntu hat beautifulsoup verpackt. Ich fand es durch Ausführen von apt-cache search

Ich sehe, es hat sowohl eine Version 2.7 und 3.3 in den Ergebnissen. Sie können durch die Installation python3-BS4

$ sudo apt-get install python3-bs4 
10

Verwenden PIP3

sudo pip3 install BeautifulSoup4 

Wenn Sie nicht PIP3 installieren Sie es mit dem following laufen kann:

sudo apt-get install python3-setuptools 
sudo easy_install3 pip 


[email protected]:~/Desktop$ sudo pip3 install BeautifulSoup4 
[sudo] password for xxx: 
Downloading/unpacking BeautifulSoup4 
    Downloading beautifulsoup4-4.3.2.tar.gz (143kB): 143kB downloaded 
    Running setup.py (path:/tmp/pip_build_root/BeautifulSoup4/setup.py) egg_info for package BeautifulSoup4 

Installing collected packages: BeautifulSoup4 
    Running setup.py install for BeautifulSoup4 
    Skipping implicit fixer: buffer 
    Skipping implicit fixer: idioms 
    Skipping implicit fixer: set_literal 
    Skipping implicit fixer: ws_comma 

Successfully installed BeautifulSoup4 
Cleaning up... 
[email protected]:~/Desktop$ python3 
Python 3.4.2 (default, Oct 8 2014, 13:08:17) 
[GCC 4.9.1] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> from bs4 import BeautifulSoup 
>>> 
+0

möglicherweise relevant http://askubuntu.com/a/116645 – ehacinom

5

Ein einzelner Befehl, um den Trick für mich, die 3.3-Version erhalten haben:

Versuchen:

sudo apt-get install python3-bs4 

und importieren Sie es dann als:

from bs4 import BeautifulSoup  
0

Ich habe oft auf den Dokumentationslink verwiesen: https://docs.python.org/3/installing/

Einige Beispiele:

python2 -m pip install SomePackage # default Python 2 
python2.7 -m pip install SomePackage # specifically Python 2.7 
python3 -m pip install SomePackage # default Python 3 
python3.4 -m pip install SomePackage # specifically Python 3.4