Skip to content

Instantly share code, notes, and snippets.

@BoQsc
Created July 21, 2024 07:05
Show Gist options
  • Save BoQsc/553745cd1559424e025fbd2763cb2799 to your computer and use it in GitHub Desktop.
Save BoQsc/553745cd1559424e025fbd2763cb2799 to your computer and use it in GitHub Desktop.
How to install pip requests using cross platform python script.
import subprocess
import sys
def install_package(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
def check_and_install_requests():
try:
import requests
print("The 'requests' library is already installed.")
except ImportError:
print("The 'requests' library is not installed. Installing now...")
install_package("requests")
print("The 'requests' library has been installed.")
check_and_install_requests()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment