【问题标题】:confusion with beautifulsoup4 installation与 beautifulsoup4 安装混淆
【发布时间】:2012-12-18 04:24:53
【问题描述】:

我已经在我的 windows7 PC 上安装了 python 2.7。现在我通过了Beautiful Soup。现在我找到了两个安装 BeautifulSoup4 的命令。 easy_install beautifulsoup4pip install beautifulsoup4。但我的困惑是我必须在哪个目录中运行这些命令。我的 python 文件夹是 C:\Python27。你能帮我在哪里运行那个命令吗?

错误

    Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Arup Rakshit>cd..

C:\Users>cd..

C:\>cd C:\Python27

C:\Python27>python.exe virtualenv.py selenv
New python executable in selenv\Scripts\python.exe
Installing setuptools....................................done.
Installing pip.........................done.

C:\Python27>cd selenv\Scripts\

C:\Python27\selenv\Scripts>pip.exe install selenium
Downloading/unpacking selenium
  Downloading selenium-2.28.0.tar.gz (2.1MB): 2.1MB downloaded
  Running setup.py egg_info for package selenium
    C:\Python27\Lib\distutils\dist.py:267: UserWarning: Unknown distribution opt
ion: 'src_root'
      warnings.warn(msg)

    warning: no files found matching 'docs\api\py\index.rst'
Installing collected packages: selenium
  Running setup.py install for selenium
    C:\Python27\Lib\distutils\dist.py:267: UserWarning: Unknown distribution opt
ion: 'src_root'
      warnings.warn(msg)

    warning: no files found matching 'docs\api\py\index.rst'
Successfully installed selenium
Cleaning up...

C:\Python27\selenv\Scripts>python.exe my_selenium_script.py
python.exe: can't open file 'my_selenium_script.py': [Errno 2] No such file or d
irectory

C:\Python27\selenv\Scripts>python.exe my_selenium_script.py
Hello

C:\Python27\selenv\Scripts>cd..

C:\Python27\selenv>pip install beautifulsoup4
'pip' is not recognized as an internal or external command,
operable program or batch file.

C:\Python27\selenv>

谢谢

【问题讨论】:

标签: python-2.7 beautifulsoup


【解决方案1】:

Beautiful Soup 4 是通过 PyPi 发布的,所以如果你不能用系统打包器安装它,你可以用 easy_install 或 pip 安装它。包名是beautifulsoup4,同一个包在Python 2和Python 3上都可以工作。

$ easy_install beautifulsoup4

$ pip install beautifulsoup4

如果您没有安装 easy_install 或 pip,您可以下载 Beautiful Soup 4source 压缩包并使用 setup.py 安装它。 [转到该文件夹​​并运行命令 setup.py install(假设 *.py 在路径扩展名中已知,否则运行 c:\python25\python setup.py install)。]

C:\Python27\beautifulsoup4-4.1.0>cd C:\Python27\beautifulsoup4-4.1.0
C:\Python27\beautifulsoup4-4.1.0>setup.py install 'here I am done!

测试:

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Arup Rakshit>cd..

C:\Users>cd..

C:\>cd C:\Python27

C:\Python27>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib import urlopen
>>> from bs4 import BeautifulSoup
>>> source = BeautifulSoup(urlopen("http://www.google.com/"))
>>> tables = source.findAll('td')
>>> import csv
>>> writer = csv.writer(open('filename.csv','w'))
>>> writer.writerow(rows)

【讨论】:

    猜你喜欢
    • 2013-11-10
    • 1970-01-01
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多