Reputation: 1394
How can I install/check/upgrade a python package from python ? I don't want to run easy_install in the console, I'm trying to make a wrapper to easy_install.
From cli I'm able to do this:
easy_install somelib
pip install somelib
I want to install packages from python. Ex:
try:
import somelib
except ImportError:
myFunctionInstall("somelib")
Upvotes: 1
Views: 466
Reputation:
You can do something like this:
import os
myFunctionInstall(module):
os.system("pip install " + module)
try:
import somelib
except ImportError:
myFunctionInstall("somelib")
You must have pip installed in your system. Hope it helps :)
Upvotes: 0
Reputation: 1125058
You generally do not want to do this. Provide proper dependencies in your setup.py
file instead, and let tools like pip
, easy_install
or zc.buildout
do the dependency work for you. People deploying the code need to be able to control where dependencies are installed, for example, to keep conflicting versions separate.
Upvotes: 1