Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating Python for use with AWS CLI

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!

like image 450
dader Avatar asked Aug 09 '26 03:08

dader


1 Answers

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.

like image 105
abarnert Avatar answered Aug 11 '26 15:08

abarnert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!