Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Installing PYTZ on a mac

Hi all,

I'm struggling to install pytz on my mac. in terminal, I'm writing 'python3 -m pip install pytz' and i'm getting a long traceback that ends in a permission error. does know whats going on/can you point me in the right direction?

thank you

2 Answers

By default, pip installs packages so that your whole system has access, but the average user (including admins) don't have permission to do that. You can also run pip directly without having to proxy the call through Python. To get around all this, you can run this line:

sudo -H pip install pytz

When asked for the password, type in the password you use to log into your Mac. It won't look like it's accepting your keystrokes, but it is. sudo escalates your privileges to be able to run whatever you want in your terminal, wherever you want, but be careful in doing so

thanks for the reply. I gave it a shot and got the message 'sudo: pip: command not found' Do you have any other suggestions?

It seems that pip isn't installed as a standalone binary on your system. It should be, which you can fix by installing Python from the official download. In the meantime, though, you can probably remedy that by doing what you originally would, but with sudo:

sudo -H python3 -m pip install pytz

If anyone else is still having similar issues with pytz after getting it installed successfully (I was getting: ModuleNotFoundError: No module named 'pytz'), I found that even though pytz was successfully installed on my machine, the default interpreter I was using to run code in PyCharm did not have that package selected for some reason. The solution was to go under Settings --> Project Interpreter and choose the default project interpreter you are using. From there, a small "+" icon at bottom of window shows and clicking it allows you to select which packages should be used. After I did this and chose pytz package, I was able to run code successfully and didn't get the "no module found" error.