我尝试安装BeautifulSoup 4
在我输入我的mac终端
后输入了$ easy_install beautifulsoup4
$ pip install beautifulsoup4
但是当我在我的python中导入它时,
from bs4 import BeautifulSoup
屏幕始终显示错误:
ImportError: cannot import name 'HTMLParseError'
然后我用google搜索错误,通过在终端输入以下代码找到可以解决问题
pip install --upgrade beautifulsoup4
但是在我输入后,它显示出来了 例外:
Traceback (most recent call last):
File "//anaconda/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "//anaconda/lib/python3.5/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "//anaconda/lib/python3.5/site-packages/pip/req/req_set.py", line 742, in install
**kwargs
File "//anaconda/lib/python3.5/site-packages/pip/req/req_install.py", line 831, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "//anaconda/lib/python3.5/site-packages/pip/req/req_install.py", line 1032, in move_wheel_files
isolated=self.isolated,
File "//anaconda/lib/python3.5/site-packages/pip/wheel.py", line 346, in move_wheel_files
clobber(source, lib_dir, True)
File "//anaconda/lib/python3.5/site-packages/pip/wheel.py", line 324, in clobber
shutil.copyfile(srcfile, destfile)
File "//anaconda/lib/python3.5/shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '//anaconda/lib/python3.5/site-packages/bs4/__init__.py'
我不知道如何修复它。谢谢你的帮助
答案 0 :(得分:0)
解决这个问题的最简单方法是使用Sudo。
sudo pip install --upgrade beautifulsoup4
但是并不总是建议sudo这样做,不应该以root用户身份安装任意代码。
我的建议是创建一个virtualenv,在使用sudo以root身份安装它们之前安装包。
您可以使用virtualenvwrapper
sudo pip install virtualenvwrapper mkvirtualenv workon python setup.py install