Ubuntu - 如何在Python 3.3而不是Python 2.7上安装Python模块(BeautifulSoup)?

dra*_*mnl 14 python ubuntu beautifulsoup python-2.7 python-3.3

我有这个代码(用BS4文档编写):

  from bs4 import BeautifulSoup
Run Code Online (Sandbox Code Playgroud)

当我运行脚本(使用python3)时,我收到错误:

  ImportError: No module named 'bs4'
Run Code Online (Sandbox Code Playgroud)

所以安装BeatifulSoup:

  sudo pip install BeatifulSoup4
Run Code Online (Sandbox Code Playgroud)

但是当我再次尝试运行脚本时,我得到了同样的错误.确实BS4安装在:

  BeautifulSoup4 in /usr/local/lib/python2.7/dist-packages
Run Code Online (Sandbox Code Playgroud)

但我想安装并使用它与python3.3(因为有其他模块不使用python2.7).

我尝试过:

  virtualenv --python=/usr/bin/python2.7 /usr/bin/python3.3
Run Code Online (Sandbox Code Playgroud)

然后再次安装BS4,但没有解决.

任何线索?提前致谢

jrw*_*ren 32

Ubuntu已经打包了beautifulsoup.我通过运行apt-cache搜索找到了它

$ apt-cache search beautifulsoup
Run Code Online (Sandbox Code Playgroud)

我看到它在结果中同时具有2.7和3.3版本.您可以通过安装python3-bs4获得3.3版本

$ sudo apt-get install python3-bs4
Run Code Online (Sandbox Code Playgroud)


blf*_*tes 11

使用pip3

sudo pip3 install BeautifulSoup4
Run Code Online (Sandbox Code Playgroud)

如果您无法运行pip3,请使用以下命令安装它:

sudo apt-get install python3-setuptools
sudo easy_install3 pip 


xxx@Ubuntu14:~/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...
xxx@Ubuntu14:~/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
>>> 
Run Code Online (Sandbox Code Playgroud)


Jim*_*mmy 5

一个命令为我做了诀窍:

尝试:

sudo apt-get install python3-bs4
Run Code Online (Sandbox Code Playgroud)

然后将其导入为:

from bs4 import BeautifulSoup    
Run Code Online (Sandbox Code Playgroud)