安装BeautifulSoup时出错

时间:2016-09-18 16:11:36

标签: python python-2.7 python-3.x

我的问题是双重的。我正在尝试安装BeautifulSoup,但面临以下错误:

Rahul-MacBook-Air:~ rahul$ sudo easy_install pip
Password:
Searching for pip
Best match: pip 8.1.2
Processing pip-8.1.2-py2.7.egg
pip 8.1.2 is already the active version in easy-install.pth
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin

Using /Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip

Rahul-MacBook-Air:~ rahul$ pip install beautifulsoup4
Collecting beautifulsoup4
  Using cached beautifulsoup4-4.5.1-py2-none-any.whl
Installing collected packages: beautifulsoup4
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py", line 742, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py", line 1032, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/wheel.py", line 346, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/wheel.py", line 317, in clobber
    ensure_dir(destdir)
  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/beautifulsoup4-4.5.1.dist-info'

有人可以告诉我,我在这里做错了什么吗?

我的下一个问题与前一个问题有关。我已经安装了Python 3.5.2

>>> print(sys.version)
3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
>>> 

然而,在终端上它显示了一个不同的版本:

Rahul-MacBook-Air:~ rahul$ python -V
Python 2.7.10

因此,当我尝试安装BeautifulSoup时,它开始指向Python 2.7,我认为这是错误的。它应该指向最新的Python版本,即3.5.2

此外,我在/usr/bin/python预先安装了Python 2.7,并在/usr/local/bin/python安装了Python 3.5.2。 我如何默认Python版本,以便每次打开终端时它都指向Python 3.5.2

谢谢, 拉胡

1 个答案:

答案 0 :(得分:2)

您在安装BeautifulSoup时遇到问题,因为您在其下运行命令的用户没有足够的权限来访问系统目录。尝试使用row_number()运行命令:

sudo

接下来,你说你已经安装了Python 3.5.2,但没有显示你用来运行它的命令。我很确定它类似于sudo pip install beautifulsoup4 (在任何情况下,不是只是python3),所以是什么让你想知道为什么python显示不同的版本号?命令python -V运行不同的Python解释器。

如果您要为Python 3.5安装任何内容,则需要python,而不是pip3

您可以将pip设为python的别名(或符号链接),并可能将Python 2.7解释器重命名为python3.5,如果尚未完成的话。