question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use subprocess.call([sys.executable, '-m', 'pip', ...]) to call pip

See original GitHub issue

Do not use “os.system('pip install {0}=={1}'.format(pkg, version))”.

Instead, I suggest doing as follows:

import pip
pip.main(['install', '{0}=={1}'.format(pkg, version)])

Sorry for my poor English.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
ghostcommented, Feb 6, 2017

Actually, what you’re supposed to do is this:

import subprocess
import sys
subprocess.call([sys.executable, '-m', 'pip', 'install', '{0}=={1}'.format(pkg, version)])
1reaction
d3rrickcommented, Jan 13, 2020

welcome, I commented because i could not find a proper example of adding pip options. my challenge is that am using a company proxy,so i needed the extra options.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Should I use pip.main() or subprocess.call() to invoke ...
It depends. pip is undocumented and may not be backwards compatible. I recommend using subprocess instead ...
Read more >
How to Install Python Packages using a Script - ActiveState
How to Install Python Packages using a Script ; # implement pip as a subprocess: subprocess.check_call([sys.executable, '-m', 'pip', 'install', ' ...
Read more >
Python install package - ProgramCreek.com
This page shows Python code examples for install package.
Read more >
How to Run Pip From The Python Interactive Shell
This function call simulates running a command from the Terminal or Command Prompt window, except it's now done from Python code. sys.executable ......
Read more >
subprocess — Subprocess management — Python 3.11.1 ...
For more advanced use cases, the underlying Popen interface can be used directly. subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found