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 Dates and Times in Python (2014) Where on Earth do Timezones Make Sense? Actually, Use pytz Instead

Maya Angelica Gurgiolo
Maya Angelica Gurgiolo
4,268 Points

Installing pytz

I can't figure out how to install pytz. In the video it says to use 'pip install pytz', but where am I supposed to type this? I've tried the Python shell, the Python command line, and Powershell. I have Python 3.4.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

pip install should be run at in a bash or powershell window. A virtualenv may used within the shell to localize the install to that end. What error are you seeing when trying in powershell?

3 Answers

First, make sure both the Python34 directory and its subdirectory Scripts are in the PATH environment variable (there's an option to add this when installing Python).

Second, try python -m pip install pytz from Powershell or a regular command prompt.

Using Python on Windows

Maya Angelica Gurgiolo
Maya Angelica Gurgiolo
4,268 Points

Thank you so much for your answer! I had Python in PATH but not the Script subdirectory. After changing that I was successfully able to use the 'python -m pip install pytz' command in Powershell.

Great! Glad it was something simple! :)

I'm using a Mac with Python 2.7. To install pytz, I opened the program called "Terminal", and then on the first line typed pip install pytz. If you're using a Mac, I hope this helps.

Michael Steinman
Michael Steinman
11,012 Points

I'm having trouble installing this module as well. Unfortunately, I don't understand the answer given. Can someone give step by step instructions on how to do this? I'm using Python 3.5 on Windows. All I know how to do is use the shell (IDLE) and write scripts by clicking File New File from the shell.

So there's a sneaky way to install modules from IDLE. Run these commands (one line at a time in IDLE):

from subprocess import call
call("pip install pytz", shell=True)

Then you can carry on with importing the module:

import pytz

Note that you need to import the module each time you use it, but only have to install it once.

Found this from this page on Google Groups: https://groups.google.com/forum/embed/#!topic/python-virtualenv/VsulL00j--8