Python Forum

Full Version: Installing Modules / packages
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there any script to make python install a pip module?

Ex :
try:
    import Module
except:
    install Module
I have found this code earlier to do so (not my work though, but it worked for me)

import subprocess
import sys

def install(package):
    subprocess.check_call(
        [sys.executable, "-m", "pip", "install", package])

install('pandas')
So in your case your exception should include the code within the code in my install function. In this case 'pandas' is an example ofcourse.