简体   繁体   English

安装BeautifulSoup时出错

[英]Error while installing BeautifulSoup

My question here is two fold. 我的问题是两个方面。 I am trying to install BeautifulSoup, but facing the below error: 我正在尝试安装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'

Can somebody please tell me what am I doing wrong here ? 有人可以告诉我我在做什么错吗?

My next question is related to the previous one. 我的下一个问题与上一个问题有关。 I have installed Python 3.5.2 我已经安装了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)]
>>> 

However on the terminal it shows me a different version: 但是在终端上,它显示了一个不同的版本:

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

So when I try to install BeautifulSoup it starts pointing to Python 2.7 which I think is wrong. 因此,当我尝试安装BeautifulSoup时,它开始指向Python 2.7,我认为这是错误的。 It should point to the latest Python version ie 3.5.2 它应该指向最新的Python版本,即3.5.2。

Also I have Python 2.7 pre-installed at /usr/bin/python and Python 3.5.2 is installed at /usr/local/bin/python . 另外我已经在/usr/bin/python预装了Python 2.7,在/usr/local/bin/python安装了Python 3.5.2。 How do I default the Python version such that every time I open my terminal it is already pointing to Python 3.5.2 如何默认Python版本,以便每次打开终端时它都已指向Python 3.5.2

Thanks, Rahul 谢谢,拉胡尔

You have trouble installing BeautifulSoup because the user you're running he commands under doesn't have enough permissions to access a system directory. 您在安装BeautifulSoup时遇到了麻烦,因为您正在运行其命令的用户没有足够的权限来访问系统目录。 Try running the command with sudo : 尝试使用sudo运行命令:

sudo pip install beautifulsoup4

Next, you're saying that you've installed Python 3.5.2, but aren't showing the command you're using to run it. 接下来,您要说的是您已经安装了Python 3.5.2,但是没有显示用于运行它的命令。 I'm pretty sure it's something like python3 (in any case, not simply python ), so what makes you wonder why python -V shows a different version number? 我敢肯定这件事情就像python3 (在任何情况下, 不能简单地python ),是什么让你想知道为什么python -V显示不同的版本号? The command python runs a different Python interpreter. python命令运行另一个Python解释器。

If you want to install anything for Python 3.5, you'll need pip3 , not pip . 如果要为Python 3.5安装任何软件,则需要pip3而不是pip

You can make python an alias (or a symbolic link) to python3.5 and probably rename the Python 2.7 interpreter to something like python2.7 , if it hasn't been done already. 您可以将python作为python3.5的别名(或符号链接),并且可能将python 2.7解释python3.5命名为python2.7 ,如果尚未完成的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM