Skip to content

Adding a Package to Python

  • by

OS: Windows (8)
Program: Python 3.4
Example Package: Requests

Introduction | Finalizing Python Installation

Before you can install a package in Python, it must be installed itself onto your computer. This tutorial will not take you through these steps, but upon successful installation of Python your computer should now have a Python Command Line and Python IDLE GUI utility. Not sure if they are there? Try looking in the standard installation location: C:\PythonXX\.
It is also necessary for your computer to have the environment variables set for Python. To do this, open command prompt (start -> run -> “cmd”) and type:

set path=%path%;C:\Python34\

note: you should change 34 to whatever version of Python you have installed

You should only have to set this environment variable once in the lifetime of Python on your computer (unless you update to a newer version of Python).

This installation will be tested shortly when we install the Python packages.

Downloading Desired Python Package

Chances are you’ve researched thoroughly what you’re trying to do with Python and have been pointed in the direction of a certain Python package that you should add to your Python to make it more powerful. Find that package and download it. How do you know you’ve got the Python package? in the root folder it will have a file inside it. (for example see Kenneth Reitz’s Requests GITHUB respository)

Assuming you’ve downloaded a *.zip file, extract that file into the same folder you downloaded it (once the Python package install is completed you can delete this). You should now be able to browse with Windows Explorer to the folder where the file is located.

How to Install a Python Package

  1. Open Command Prompt (start -> run -> “cmd“)
  2. Change directory to the location you just extracted your Python package to (type: cd C:\Users\xxx\Downloads\package_name)
  3. Command Prompt should now show you: C:\Users\xxx\Downloads\requests-master>
  4. type: python install
  5. Watch with fascination as all the lines scroll by your screen and Python installs your desired Package (this also confirms that your environment variable has been successfully set and Python is installed correctly on your machine)
  6. Double check the install has happened by browsing to the site-packages folder of Python (C:\Python34\Lib\site-packages\requests.egg)
  7. Open IDLE GUI Utility (installs with Python and should be in the Python Program Files directory)
  8. Import the Python package with IDLE by typing: import requests (hopefully no errors arise here and a new command line awaits)

To make sure that your package (requests) has been successfully installed into Python, type help() then type requests – or – modules and either make sure the module you just installed (requests) exists and has a help file.

note: for this example, the Python package Requests was installed, you should change this name to your desired package to install, and repeat this process until you have installed all the packages you so desire.

Hope this helps, and welcome to Python!



Leave a Reply

Your email address will not be published. Required fields are marked *

two × three =