2016-09-18 155 views
0

这里我的问题有两点。我试图安装BeautifulSoup,但面临以下错误:安装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)] 
>>> 

但是在终端上就说明我一个不同的版本:

​​

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

另外,我已经预装了Python 2.7,编号为/usr/bin/python,Python 3.5.2安装在/usr/local/bin/python。 如何默认Python版本,使得每次我打开我的终端时它已经指向的Python 3.5.2

感谢, 拉胡尔

+0

'权限被拒绝' – Jeon

回答

1

你可以选择安装BeautifulSoup因为用户你正在运行费神下的命令没有足够的权限来访问系统目录。尝试用sudo运行命令:

sudo pip install beautifulsoup4 

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

如果你想为Python 3.5安装任何东西,你需要pip3而不是pip

您可以使python作为python3.5的别名(或符号链接),并且可能会将Python 2.7解释器重命名为python2.7之类的名称(如果尚未完成)。

+0

我其实是python的新手,并试图在这里学习的东西。根据你的建议我执行命令'sudo pip3安装beautifulsoup4',我可以成功安装'成功安装beautifulsoup4-4.5.1' 但是对于我的下一个问题,我如何默认python版本到3.5.2 我确实试图遵循你的答案,但如果你能详细说明答案,那将是非常有用的。 –

+0

@RahulDevMishra,你是什么意思'如何默认Python版本...'?你是否希望'python'命令打开Python 3.5而不是2.7?我认为'pip'只会继续为Python 2.7安装模块,而不管'python'命令是做什么的。另外,'python'文件可能是一个全功能的Python解释器(不是符号链接),如果你用一个指向Python 3.5的符号链接来覆盖它,这可能会破坏Python 2.7的安装......在我看来, “python3.5”和“python”更好,所以你总是知道哪个命令运行哪个Python版本。 – ForceBru

+0

谢谢@ForceBru –