Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Dates and Times in Python Where on Earth do Timezones Make Sense? pytz Format

Michael Steinman
Michael Steinman
11,012 Points

install pytz

I'm having trouble installing this module. I've noticed that someone has already asked this question, but 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.

7 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,064 Points

Here is how I installed pytz on windows

  • ensure running Python 3.x
PS C:\> python -V
Python 3.5.0
  • ensure pip has correct version
PS C:\> pip --version
pip 8.1.1 from c:\python35\lib\site-packages (python 3.5)

If needed, upgrade pip using python -m pip install --upgrade pip

  • ensure pip can find pytz in library
PS C:\> pip search pytz | grep "^pytz "
pytz (2015.7)                      - World timezone definitions, modern and historical
  • Install pytz
PS C:\> pip install pytz
Collecting pytz
  Using cached pytz-2016.4-py2.py3-none-any.whl
Installing collected packages: pytz
Successfully installed pytz-2016.4
  • test installation
PS C:\> python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytz
>>>  # No errors means pytz has been installed.

Notes

  • I don't use Windows as my base OS (I prefer Linux). I had to update my environment variables (Control Panel --> System and Security --> System --> Advanced Settings --> Environment Variables) to correct PYTHONPATH. It still had some Python 2.7 directories on the path.
  • A virtualenv could be used to isolate the use of Python 3.5 from Python 2.7 if need be.
Michael Steinman
Michael Steinman
11,012 Points

Uuuuuuhhhhhh so where are you typing all of this?

Maybe I need to give up on computers and just go live in a cabin in the mountains

Chris Freeman
Chris Freeman
Treehouse Moderator 68,064 Points

I've edited my post. The prompts starting with "PS" are in the Windows PowerShell, the "<<<" are the Python REPL prompt.

Michael Steinman
Michael Steinman
11,012 Points

Every time I try to type any of the commands you listed, I get an error message saying the term is not recognized.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,064 Points

So you are in a PowerShell window and you type "python -V" at the PS prompt and you're getting an error. Can you cut and paste the contents of the shell window (include prompt, command, and response)? Thanks.

Michael Steinman
Michael Steinman
11,012 Points

PS C:> python -V The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spel ling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:7

  • python <<<< -V
    • CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException
Chris Freeman
Chris Freeman
Treehouse Moderator 68,064 Points

You mentioned having Python 3.5 installed. Are you only invoking the IDLE program then accessing Python through IDLE?

It seems that IDLE has been installed but Python is not executable directly. Be sure the Python install directory and the Python/Lib directory are on your PATH:

Inside of IDLE at the Python shell prompt, type:

>>> import sys
>>> sys.path

and post the results of the sys.path statement.

Michael Steinman
Michael Steinman
11,012 Points

import sys sys.path ['', 'C:\Users\Sarah\AppData\Local\Programs\Python\Python35-32\Lib\idlelib', 'C:\Users\Sarah\AppData\Local\Programs\Python\Python35-32\python35.zip', 'C:\Users\Sarah\AppData\Local\Programs\Python\Python35-32\DLLs', 'C:\Users\Sarah\AppData\Local\Programs\Python\Python35-32\lib', 'C:\Users\Sarah\AppData\Local\Programs\Python\Python35-32', 'C:\Users\Sarah\AppData\Local\Programs\Python\Python35-32\lib\site-packages']

Chris Freeman
Chris Freeman
Treehouse Moderator 68,064 Points

It seems that the IDLE installation didn't include the top Python directory where python.exe exists. I don't see Python itself is not on your path. Does the directory C:\Users\Sarah\AppData\Local\Programs\Python\Python35-32\ have a python.exe present? what is the contents of this directory?

Have you watched the Treehouse mini-course Setting up a Local Python Environment (Windows)? It may answer where the setup went awry.

Michael Steinman
Michael Steinman
11,012 Points

Chris Freeman: Success! I uninstalled python and then reinstalled it. I made sure to check "Add python 3.5 to PATH." I probably didn't do this the first time I installed python. I followed your original instructions, and didn't get any errors after >>> import pytz so I assume all is well.

Thanks for your patience. I guess I may not have to move to the mountains just yet.

Amber Diehl
Amber Diehl
15,402 Points

Hi Everyone,

I have downloaded pyTZ and am attempting to install it. I'm getting an error--to investigate, I opened up the init file in pyCharm and it is saying that the syntax used for exception handling is not valid in Python 3.5. I might be able to figure out how to fix it but being a newbie to Python would prefer not to venture there yet. Is there anyone on 3.5+ that can help me?

Thanks in advance!