Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22871

Python Morsels: Installing Python packages

$
0
0

When your code depends other Python libraries to run, you'll want to reach for pip and venv to install those third-party Python packages.

Our program depends on a third-party package

Here we have a program called name.py:

importrequestsprint(requests.get("https://pseudorandom.name").text.strip())
importrequestsprint(requests.get("https://pseudorandom.name").text.strip())

This program doesn't work right now:

$ python3 name.py
Traceback (most recent call last):
  File "/home/trey/name.py", line 1, in<module>
    import requests
ModuleNotFoundError: No module named 'requests'
$ python3 name.py
Traceback (most recent call last):
  File "/home/trey/name.py", line 1, in<module>
    import requests
ModuleNotFoundError: No module named 'requests'

It doesn't work because it uses the requests module, which isn't included with Python. This is a popular module that's included in the requests package, that you can install from the Python Package Index by using a tool called pip which comes bundled with Python.

Installing packages using pip

We can use pip by …

Read the full article: https://www.pythonmorsels.com/installing-python-packages/


Viewing all articles
Browse latest Browse all 22871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>