Python 安装BeautifulSoup时出错

Python 安装BeautifulSoup时出错,python,python-2.7,python-3.x,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 scrip

我的问题有两个方面。我正在尝试安装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

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

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

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

如果您想为Python3.5安装任何东西,您需要的是
pip3
,而不是
pip


您可以将
python
作为
python3.5
的别名(或符号链接),并可能将python2.7解释器重命名为类似于
python2.7
,如果尚未执行此操作。

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

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

如果您想为Python3.5安装任何东西,您需要的是
pip3
,而不是
pip


您可以将
python
作为
python3.5
的别名(或符号链接),并可能将python2.7解释器重命名为类似于
python2.7
,如果还没有这样做的话。

权限被拒绝
权限被拒绝
我实际上是python的新手,正在尝试在这里学习。根据您的建议,我执行了命令
sudo pip3 install beautifulsoup4
,并且我可以成功地安装它
成功地安装beautifulsoup4-4.5.1
,但是在我的下一个问题上,我如何将python版本默认为3.5.2我尝试按照您的答案进行操作,但是如果您能够详细说明答案,这将非常有用。@RahulDevMishra,你说的“如何默认Python版本…”是什么意思?是否希望
python
命令打开python3.5而不是2.7?我认为无论
Python
命令做什么,
pip
都将继续只为python2.7安装模块。另外,
python
文件可能是一个功能齐全的python解释器(不是符号链接),如果您用指向python3.5的符号链接覆盖它,这可能会破坏python2.7的安装。。。在我看来,最好同时使用
python3.5
python
,这样您就可以知道哪个命令运行哪个python版本。实际上,我对python还不太熟悉,并尝试在这里学习。根据您的建议,我执行了命令
sudo pip3 install beautifulsoup4
,并且我可以成功地安装它
成功地安装beautifulsoup4-4.5.1
,但是在我的下一个问题上,我如何将python版本默认为3.5.2我尝试按照您的答案进行操作,但是如果您能够详细说明答案,这将非常有用。@RahulDevMishra,你说的“如何默认Python版本…”是什么意思?是否希望
python
命令打开python3.5而不是2.7?我认为无论
Python
命令做什么,
pip
都将继续只为python2.7安装模块。另外,
python
文件可能是一个功能齐全的python解释器(不是符号链接),如果您用指向python3.5的符号链接覆盖它,这可能会破坏python2.7的安装。。。在我看来,最好同时使用
python3.5
python
,这样您就可以知道哪个命令运行哪个python版本。