更新Python以与AWS CLI一起使用 [英] Updating Python for use with AWS CLI

查看:79
本文介绍了更新Python以与AWS CLI一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在终端(Mac OS X v10.6.8)中使用AWS CLI S3,并且在运行基本命令(例如aws s3 ls)时配置了所有适当的凭证后,它不会输出任何内容./p>

当我执行稍微复杂一些的命令(例如aws s3 mb s3://newbucketname)时,它输出:__init__() keywords must be strings.

基于一些研究,我怀疑原因是默认情况下安装了Python 2.6.1,因此我下载了v3.3.2,进行了安装,并使用"Update Shell Profile.command"功能设置了正确的PATH变量.

现在安装并配置了新版本的Python后,我仍然得到相同的结果.尽管$ PATH变量指向新版本(v3.3.2),该终端仍似乎使用旧版本的Python.

任何帮助将不胜感激.我猜想这与终端没有使用新版本的Python有关,因此AWS CLI功能不起作用,但是可能是我不知道的其他原因.

谢谢!

解决方案

如果您将aws与Python 2.6随附的easy_install一起安装,则将被硬编码为使用Python 2.6,其第一行将类似于这个:

#!/usr/bin/python2.6

shebang行表示该脚本将使用/usr/bin/python2.6运行.安装Python 3.3不会更改/usr/bin/python2.6的内容.它与PATH上的内容或PATH上的第一件事无关. PATH仅在脚本在shebang行上使用/usr/bin/env时起作用.而且/usr/bin/env python2.6当然仍然可以找到Python 2.6.实际上,即使/usr/bin/env python仍然可以找到Python 2.6,因为3.3没有名为python的任何东西,只有python3.

同时,即使您设法破解它以代替使用Python 3.3(例如,通过将第一行更改为/Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3/usr/bin/env python3),也只会使其完全损坏. aws脚本要求将aws软件包安装到您的站点软件包中.您已将它们安装到2.6站点程序包中,但未安装到3.3站点程序包中. (最重要的是,许多软件包为Python 2.x和3.x安装了不同的代码,因此2.6脚本即使在3.3软件包中也可能无法使用.)

无论如何,解决此问题的正确方法是从Python 2.6卸载aws,然后为Python 3.3重新安装.

如果按照建议使用pip,这将是微不足道的:

pip-2.6 uninstall awscli
pip-3.3 install awscli

不幸的是,因为您使用的是easy_install,所以必须手动将其卸载.

实际上,您不需要卸载软件包,只需卸载以/usr/local/binPATH上其他地方结尾的脚本即可.我怀疑rm /usr/local/bin/aws*会解决这个问题,但要小心-确保那里没有安装任何以aws开头但不属于软件包一部分的东西.

同时,为了将来安装pip并使用它.对于Apple的Python 2.6,请使用sudo easy_install pip进行安装.对于Python 3.3,请按照 pip 网站上的说明进行操作.

I'm trying to use AWS CLI S3 within the Terminal (Mac OS X v10.6.8) and after configuring all of the proper credentials when I run basic commands (e.g., aws s3 ls) it does not output anything.

When I do a slightly more complicated command (e.g., aws s3 mb s3://newbucketname) it outputs: __init__() keywords must be strings.

Based on some research I suspected the cause is that Python 2.6.1 is installed by default, so I downloaded v3.3.2, installed it, and used the 'Update Shell Profile.command' feature to set the correct PATH variable.

Now with the new version of Python installed and configured I still get the same results. The Terminal still appears to be using the old version of Python, despite the $PATH variable pointing to the new version (v3.3.2).

Any help would be greatly appreciated. I'm guessing that it has to do with the Terminal not using the new version of Python and thus the AWS CLI functionality doesn't work, but there may be a different cause that I'm not aware of.

Thank you!

解决方案

If you installed aws with the easy_install that came with Python 2.6, it will be hardcoded to use Python 2.6—its first line will be something like this:

#!/usr/bin/python2.6

This shebang line means that the script will run with /usr/bin/python2.6. Installing Python 3.3 won't change what's at /usr/bin/python2.6. It has nothing to do with what's on the PATH, or what the first thing called python is on the PATH. The PATH only comes into play if a script uses /usr/bin/env on the shebang line. And /usr/bin/env python2.6 would of course still find Python 2.6. In fact, even /usr/bin/env python would still find Python 2.6, because 3.3 doesn't have anything named python, just python3.

Meanwhile, even if you managed to hack it up to run with Python 3.3 instead (e.g., by changing that first line to /Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3 or /usr/bin/env python3), that would just make it break completely. The aws script requires the aws package to be installed into your site-packages. You've installed them into your 2.6 site-packages, but not your 3.3 site-packages. (On top of that, many packages install different code for Python 2.x vs. 3.x, so the 2.6 script might not work with the 3.3 package even if it were there.)

Anyway, the right way to fix this is to uninstall aws from Python 2.6, and re-install it for Python 3.3.

If you'd used pip as recommended, this would be trivial:

pip-2.6 uninstall awscli
pip-3.3 install awscli

Unfortunately, because you used easy_install instead, you have to uninstall it manually.

And really, you don't need to uninstall the packages, just the scripts that ended up in /usr/local/bin or somewhere else on your PATH. I suspect rm /usr/local/bin/aws* will take care of that, but be careful—make sure there's nothing else installed there that starts with aws but isn't part of the package.

Meanwhile, for the future, install pip and use that. For Apple's Python 2.6, use sudo easy_install pip to install it. For Python 3.3, follow the instructions at the pip site.

这篇关于更新Python以与AWS CLI一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆