wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, volunteer authors worked to edit and improve it over time.
This article has been viewed 32,339 times.
Learn more...
If you're a budding computer scientist working with Python 3 and want to add functionality and power to your projects that doesn't exist in the base built-in Python modules, you may want to try to install external third-party modules and libraries to help you achieve the level of productivity you want in your program. This guide is meant to help demonstrate the process for package installation using the pip tool, the ubiquitous and extensive Python package manager.
This guide assumes the reader knows elementary Python programming and has some familiarity with the command shell on their Windows system (CMD, PowerShell, etc.).
Steps
If Python is Not Installed
Depending on whether Python is already on your computer or not, you may have to take different steps. Use Method 1 or Method 2 depending on your circumstance.
-
1Go to python.org to select the version of Python you wish to download. Typically, the latest version is preferable as it is less bug-prone and has more features, but nearly all the Python 3.X installations should work just fine. Remember to get the 32-bit or 64-bit depending on your system.
-
2Run the installer once it’s finished downloading. This is to initiate the installation process. For the most part this is self-explanatory, but there’s a crucial check to make.Advertisement
-
3Check off 'Add Python 3.x to PATH'. This will allow you to use Python and pip from a command shell easily, which is important for installing packages.
If Python is Already Installed
-
1Test to see if pip can be used from the command line already by typing
pip -V
into a command shell. If this command works and version details for your pip installation are shown, you can skip to Part 2 of this guide. Continue below if the command fails. -
2Locate the directory in which you installed Python originally. To locate the installation path, press "Window + s" key together and then type Python if you are on Windows 7+. Remember this path; that’s the folder where the executables are for running Python and pip. This may be difficult to find, but typical locations that you may find Python installed at are:
- C:\PythonXX
- C:\Users\<YOUR USER>\AppData\Local\Programs\Python\PythonXX
-
3Open the Environment Variables dialog. This can be done by searching up "system variables" and clicking on the first option, then clicking on the Environment Variables… button.
-
4Add the Python path you just copied to the user 'Path' variable. You can do this by selecting the 'Path' variable, clicking Edit… → New and pasting the path. Paste it again in a new field with "\Scripts" at the end of it. You may need to restart your computer after this step.
- After following these steps, you will have a local Python installation with full pip functionality that you can use from a command shell.
Finding and Installing Modules for Python
For this example, the module installed will be numpy — an extremely rich mathematical library with robust functionality that many other libraries depend on. You can install whatever you’d like however.
-
1Research what kind of modules you want to install on your computer. There are many, many modules out there that all do great things. In order to deal with the problems you want your program to solve, try looking up modules online by searching "how to <do something> python"; more often than not, websites can be full of recommendations and helpful advice.
-
2Look up the package name for the module you want to install. Go to pypi.org and look up the module you want. The name of the package that contains it as well as the command needed to install it are at the top of the page. It will look something like
pip install <package-name>
. -
3Open the command shell on your computer and run the command from the PyPI page. This will initiate the installation process. Remember to close all instances of Python that are running when you do this.
After completing this part, the module will be installed and ready for use in your Python projects.
Using Newly Installed Modules in Python Code
After getting your hands on a new Python module, the next step may seem obvious — use the module! — but it may be likely that you might not know exactly how the module is imported, initiated or otherwise. Here are some steps to help you get started.
-
1Open a fresh Python instance (IDLE or shell) and type in the import statement for your module. More often than not, the module name for importing is the same as the package name. You can always use the documentation to verify this. Once you type in the line of code to set up your import, you’re good to go. Add some other code as you need to.
-
2Execute your code in your editing environment. If no errors occur, congratulations! You’ve managed to install a brand-new third-party Python module.
- With this, your foray into Python module installation and usage is complete!