1

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")
1
  • I've completed the post with some sample code of what I want to do. Commented May 28, 2012 at 12:53

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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 :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.