Created
July 21, 2024 07:05
-
-
Save BoQsc/553745cd1559424e025fbd2763cb2799 to your computer and use it in GitHub Desktop.
How to install pip requests using cross platform python script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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