Skip to main content
Add a way to call `pip` from within a script
Source Link
Jace Browning
  • 2.2k
  • 1
  • 16
  • 25

This is the job of the package manager. In the case of Python: pip.

If you package the library you are building and specify its dependencies, your users (grandpa), will simply need to run:

$ pip install --upgrade <name-of-package>

to get the latest version you've released and all of its dependencies. If you don't want to publish your code online, pip can also install from local sources:

$ pip install zipped_package_emailed_to_grandpa.zip

or, if you really need to package this in a single (Python 3.4+) script, you could call pip from within:

#!/usr/bin/env python3

def main():
   ...

if __name__ == '__main__':
    import sys, subprocess
    dependencies = ['dep_1', 'dep_2']
    subprocess.call([sys.executable, '-m', 'pip', 'install'] + dependencies)
    import dep_1, dep_2
    main()

but this is definitely uncommon.

This is the job of the package manager. In the case of Python: pip.

If you package the library you are building and specify its dependencies, your users (grandpa), will simply need to run:

$ pip install --upgrade <name-of-package>

to get the latest version you've released and all of its dependencies. If you don't want to publish your code online, pip can also install from local sources:

$ pip install zipped_package_emailed_to_grandpa.zip

This is the job of the package manager. In the case of Python: pip.

If you package the library you are building and specify its dependencies, your users (grandpa), will simply need to run:

$ pip install --upgrade <name-of-package>

to get the latest version you've released and all of its dependencies. If you don't want to publish your code online, pip can also install from local sources:

$ pip install zipped_package_emailed_to_grandpa.zip

or, if you really need to package this in a single (Python 3.4+) script, you could call pip from within:

#!/usr/bin/env python3

def main():
   ...

if __name__ == '__main__':
    import sys, subprocess
    dependencies = ['dep_1', 'dep_2']
    subprocess.call([sys.executable, '-m', 'pip', 'install'] + dependencies)
    import dep_1, dep_2
    main()

but this is definitely uncommon.

[Edit removed during grace period]
Source Link
Jace Browning
  • 2.2k
  • 1
  • 16
  • 25
Source Link
Jace Browning
  • 2.2k
  • 1
  • 16
  • 25

This is the job of the package manager. In the case of Python: pip.

If you package the library you are building and specify its dependencies, your users (grandpa), will simply need to run:

$ pip install --upgrade <name-of-package>

to get the latest version you've released and all of its dependencies. If you don't want to publish your code online, pip can also install from local sources:

$ pip install zipped_package_emailed_to_grandpa.zip