使用pip下载boto库失败
我用 sudo easy_install pip
安装了 pip,这样我就可以下载 Python 的 boto 库。然后我执行了 pip install -U boto
,结果出现了这个错误:
Installing collected packages: boto
Cleaning up...
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 1435, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 671, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 901, in move_wheel_files
pycompile=self.pycompile,
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 215, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 205, in clobber
os.makedirs(destdir)
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/boto'
Storing debug log for failure in /Users/DRizzuto/Library/Logs/pip.log
于是我尝试用 easy_install boto
来安装,但又出现了这个错误:
The following error occurred while trying to add or remove files in the
installation directory:
[Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-2024.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/Library/Python/2.7/site-packages/
Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.
我现在不知道该怎么安装 boto 了。有没有人能帮我解释一下,怎么解决这些错误或者绕过它们?
4 个回答
请参考这个博客。你遇到的问题是权限方面的。
http://nitheeshp.blogspot.in/2014/05/configuring-and-installing-boto-on.html
在使用boto的时候,你其实不需要用到sudo
。
使用sudo
(把模块安装到全局路径)可能对一些确实需要全局路径的模块来说是个好办法(这意味着我们确定这些模块会在整个系统中使用 - 通常像ansible
、virtualenv
,可能还有fabric
- 不过这也可以争论)。
大多数其他的依赖项(包括boto
)应该始终在requirements.txt
文件中定义,这个文件应该和应用程序一起打包。每个应用程序可能(并且肯定会)有不同的依赖项,不同版本的模块,你不想在全局路径中造成任何冲突或混乱。
不过,使用virtualenv
的话,你可以创建一个虚拟环境,只把最重要的东西(比如实际的virtualenv
模块)放在全局环境中,而把所有项目相关的依赖项放在“虚拟”环境中。
想了解更多关于virtualenv
的信息,可以查看这个链接:http://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/
除了virtualenv
,还有其他一些方法可以用来隔离环境,但关键是你应该进行环境隔离。
默认情况下,pip会尝试把软件包安装在 /Library/Python/2.7/site-packages/
这个文件夹里,正如你在错误信息中看到的。这个文件夹是属于“根用户”的,普通用户没有权限在这里安装东西。
sudo
是用来以根用户的身份运行命令的,所以在这种情况下,你只需要输入
sudo pip install -U boto
你需要以管理员身份运行pip命令。(或者用类似的命令,比如sudo)
下面是一个在Mac上运行的例子:
sudo pip install -U boto