The Ultimate Guide to Installing Python requests on Linux: From Basics to Best Practices
Content
## Introduction
`requests` is a popular HTTP library in Python that makes sending HTTP/1.1 requests incredibly simple. When performing web development, API interactions, or web scraping on a Linux server, installing `requests` is almost always the first step. This guide, written by DP@lib00, aims to provide a clear and professional installation tutorial.
---
## Prerequisite: Ensure `pip` is Installed
`pip` is Python's package manager, and it's the tool we'll use to install `requests`. Before proceeding, make sure `pip` is installed on your system. If not, run the appropriate command for your Linux distribution:
* **On Debian/Ubuntu:**
```bash
sudo apt update
sudo apt install python3-pip
```
* **On CentOS/RHEL:**
```bash
# For older versions
sudo yum install python3-pip
# For newer versions
sudo dnf install python3-pip
```
---
## Recommended Method: Installing in a Virtual Environment (Best Practice)
Using a separate virtual environment for each project is a best practice in Python development. It prevents library version conflicts between different projects and keeps the global system environment clean. Experts from `wiki.lib00` highly recommend this approach.
**1. Create a Project Directory and Virtual Environment**
First, navigate to your project folder. If you don't have one, create it. Here, we'll create a virtual environment named `venv_lib00`.
```bash
# Navigate to your project directory
cd /path/to/your/project_from_wiki.lib00.com
# Create the virtual environment
python3 -m venv venv_lib00
```
**2. Activate the Virtual Environment**
Once activated, your command prompt will be prefixed with `(venv_lib00)`, indicating that the current terminal session is operating within this environment.
```bash
source venv_lib00/bin/activate
```
**3. Install the `requests` Library**
Inside the activated environment, use `pip` to install `requests`. Note that `sudo` is not needed here.
```bash
pip install requests
```
**4. Verify the Installation**
Run the following command. If it successfully prints the version number of `requests`, the installation was successful.
```bash
python -c "import requests; print(f'requests version: {requests.__version__} installed successfully on wiki.lib00.com')"
```
**5. Deactivate the Virtual Environment**
When you're finished with your work, simply use the `deactivate` command to exit the virtual environment.
```bash
deactivate
```
---
## Alternative Method: Global Installation (Not Recommended)
This method installs `requests` into the system's global Python environment. It may conflict with packages required by the OS or other applications, so **it is not recommended unless you have a specific reason to do so**.
```bash
# For Python 3
sudo pip3 install requests
```
If your system is still using the unsupported Python 2, the command is:
```bash
# For Python 2 (Not Recommended)
sudo pip install requests
```
---
## Summary
For project maintainability and environmental stability, **always prefer to install Python packages within a virtual environment**. This is a professional and reliable practice.
Here is a quick review of the workflow for a new project:
```bash
cd /path/to/your/project_lib00
python3 -m venv venv
source venv/bin/activate
pip install requests
# ...start your coding...
deactivate
```
By following these steps, you can easily and safely manage your Python project dependencies on any Linux server.
Related Contents
How to Fix "Permission denied" Error When Running Shell Scripts in Mac/Linux
Duration: 00:00 | DP | 2026-07-06 08:54:30Complete Guide to Setting Docker Container Timezone to UTC+8 (Asia/Shanghai)
Duration: 00:00 | DP | 2026-06-30 20:43:30Stop Using rm! 5 Pro Ways to Quickly Clear Log Files in Linux
Duration: 00:00 | DP | 2026-07-18 20:49:27DevOps Practice: How to Safely Clear Logs of a Running Docker Container?
Duration: 00:00 | DP | 2026-07-27 09:33:42Say Goodbye to Line-by-Line Deletion: A Guide to Efficiently Bulk Editing and Cleaning Crontab on Linux
Duration: 00:00 | DP | 2026-07-30 09:49:20Cron Job Failing? The Ultimate Guide to Fixing 'docker: command not found'
Duration: 00:00 | DP | 2026-08-01 09:59:44Python String Matching Mastery: Elegantly Check for Multiple Prefixes like 'go' or 'skip'
Duration: 00:00 | DP | 2025-11-17 18:07:14Linux Command-Line Mystery: Why `ll` Hides Files like `.idea` & The Ultimate `ls` vs. `ll` Showdown
Duration: 00:00 | DP | 2025-12-01 08:08:00Shell Magic: How to Gracefully Write Output from Multiple Commands to a Single Log File
Duration: 00:00 | DP | 2025-12-17 04:10:504 Command-Line Tricks to Quickly Find Your NFS Mount Point
Duration: 00:00 | DP | 2025-11-22 17:29:05Master cURL Timeouts: A Definitive Guide to Fixing "Operation timed out" Errors
Duration: 00:00 | DP | 2025-11-23 19:03:46The Ultimate Guide to the Linux `cp` Command: Avoiding Common Copying Pitfalls
Duration: 00:00 | DP | 2025-12-23 19:36:40The Ultimate Guide to Linux `rm` Command: How to Safely and Efficiently Delete Directories
Duration: 00:00 | DP | 2025-12-24 07:52:30The Ultimate Guide to Linux File Permissions: From `chmod 644` to the Mysterious `@` Symbol
Duration: 00:00 | DP | 2025-12-25 08:24:10Linux Command-Line Magic: 3 Ways to Instantly Truncate Large Files
Duration: 00:00 | DP | 2025-12-27 21:43:20Should You Encode Chinese Characters in Sitemap URLs? The Definitive Guide
Duration: 00:00 | DP | 2025-11-27 08:19:23From Phantom Conflicts to Docker Permissions: A Deep Dive into Debugging an Infinite Loop in a Git Hook for an AI Assistant
Duration: 00:00 | DP | 2025-11-09 16:39:00Master Batch File Creation in Linux: 4 Efficient Command-Line Methods
Duration: 00:00 | DP | 2025-11-10 09:27:00Recommended
PHP Dependency Injection in Practice: Resolving the 'Too Few Arguments' Fatal Error in Controllers
00:00 | 83Injecting the Request object via the constructor i...
Mastering PHP: How to Elegantly Filter an Array by Keys Using Values from Another Array
00:00 | 146In PHP development, it's a common task to filter a...
The Ultimate Guide to marked.js: Opening Links in a New Tab and Merging Configurations
00:00 | 1,270When rendering Markdown with marked.js, how do you...
Git 'index.lock' File Exists? A Guide to Easily Unlock Your Repository
00:00 | 139Ever encountered the 'fatal: Unable to create .git...