3

I saw an older question, suggesting to use pip.main(package), however this does not upgrade a package. I could not find anything. Thanks in advance.

4
  • 1
    You really should not be updating packages from inside code unless it is strictly necessary. It can cause incompatibility errors. You can use system calls though Commented Aug 22, 2016 at 23:16
  • @J. C. Rocamonde How would I go about using system calls? Commented Aug 23, 2016 at 3:41
  • I guess a better answer than mine solves the problem, but you can call the pip command with the python subprocess module Commented Aug 23, 2016 at 10:09
  • OK, thanks. I looked at that, but it seemed I needed to enter the password many times because I was looping it to upgrade all, and python was in admin only folder Commented Aug 23, 2016 at 21:11

1 Answer 1

3

Try pip.main(['install', '--upgrade', package]) instead. pip.main just takes arguments exactly like the command line version.

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

4 Comments

Shouldn't package go between quotes?
I was assuming package was a variable containing the name of whatever package OP wants to upgrade.
Yes, package was a variable that had a string inside it. Here is the class; def pipInstall(package): pip.main(['install', '--upgrade', package])
Did that do it for you then? It works on my machine.

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.