How to Install a Library in Python (5 Steps)

5/5 - (1 vote)
pip install <package>
# Example: pip install pandas
# Example: pip install requests

5 Simple Steps to Install a Library in Python

Follow this 5 step procedure to install a library, module, or package in Python:

  1. Download Python if you haven’t already and install it in your environment.
  2. Add the python or pip commands to your environment variable so you can access them from the command line (Win) or terminal (macOS, Linux).
  3. After Python is installed, run the following PIP command in your shell/terminal/cmd: python -m pip install xxx. Replace xxx with your library name (e.g., python -m pip install pandas to install pandas).
  4. This may fail for various reasons. To work around those, try either pip install xxx, pip3 install xxx, or python3 -m pip install xxx. If none works, go back to step 2.
  5. Verify the library xxx is installed using the command pip list or pip3 list, or the Python expression import xxx; print(xxx.__version__). Of course, replace xxx with your library name (e.g., pandas or requests).

Related Tutorials

If you run into the ModuleNotFoundError, check out our full guide on how to resolve it here:

🌍 Recommended Tutorial: ModuleNotFoundError: No module named ‘xxx’

If you want to check the package version, check out our full guide on this here:

🌍 Recommended Tutorial: 8 Best Ways to Check the Package Version in Python

Do you want to install a specific package or module version? Try this tutorial:

🌍 Recommended Tutorial: Installing Specific Package Versions With PIP

Do you have a wheel (.whl) file to install the Python package? Check out this tutorial on the Finxter blog!

🌍 Recommended Tutorial: How to Install a Python Package with a .whl File?

Finally, are you on PyCharm? Use this simple approach to install a package there:

🌍 Recommended Tutorial: How to Install a Library on PyCharm?

Thanks for visiting our site! Feel free to come back more by subscribing to our free learning community:

We have cheat sheets! 🙂


Programming Humor

💡 Programming is 10% science, 20% ingenuity, and 70% getting the ingenuity to work with the science.

~~~

  • Question: Why do Java programmers wear glasses?
  • Answer: Because they cannot C# …!

Feel free to check out our blog article with more coding jokes. 😉