2014-10-22 10 views
12

Ho questo codice (come scritto nel BS4 documentaion):Ubuntu - Come installare un modulo Python (BeautifulSoup) su Python 3.3 anziché su Python 2.7?

from bs4 import BeautifulSoup 

Quando eseguo lo script (utilizzando python3) ottengo l'errore:

ImportError: No module named 'bs4' 

Così installato BeatifulSoup da:

sudo pip install BeatifulSoup4 

Ma quando provo a eseguire di nuovo lo script ottengo lo stesso errore. Infatti BS4 è installato in:

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

Ma io voglio installare e utilizzare con python3.3 (come ci sono altro modulo che non stanno lavorando con python2.7).

Ho provato con:

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

e quindi installare nuovamente BS4, ma nulla risolto.

Qualsiasi indizio? Grazie in anticipo

+0

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

+0

http://stackoverflow.com/questions/10919569/ how-to-pip-install-to-specific-python –

risposta

27

Ubuntu ha BeautifulSoup confezionato. L'ho trovato eseguendo la ricerca apt-cache

$ apt-cache search beautifulsoup 

Vedo che ha sia una versione 2.7 e 3.3 nei risultati. È possibile ottenere la versione 3.3 con l'installazione di python3-BS4

$ sudo apt-get install python3-bs4 
10

Usa PIP3

sudo pip3 install BeautifulSoup4 

Se non è possibile eseguire PIP3 installarlo con l'following:

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

probabilmente pertinente http://askubuntu.com/a/116645 – ehacinom

5

un unico comando ha fatto il trucco per me:

Prova:

sudo apt-get install python3-bs4 

e quindi importarlo come:

from bs4 import BeautifulSoup  
0

Ho spesso fatto riferimento al collegamento della documentazione: https://docs.python.org/3/installing/

Alcuni esempi:

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 
Problemi correlati