Skip to content

Instantly share code, notes, and snippets.

@frgomes
Last active August 27, 2017 17:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frgomes/6140463 to your computer and use it in GitHub Desktop.
Save frgomes/6140463 to your computer and use it in GitHub Desktop.
Python - Installing packages programmatically
#!/usr/bin/env python
from __future__ import print_function
REQUIREMENTS = [ 'distribute', 'version', 'Cython', 'sortedcollection' ]
try:
from setuptools import find_packages
from distutils.core import setup
from Cython.Distutils import build_ext as cython_build
import sortedcollection
except:
import os, pip
pip_args = [ '-vvv' ]
proxy = os.environ['http_proxy']
if proxy:
pip_args.append('--proxy')
pip_args.append(proxy)
pip_args.append('install')
for req in REQUIREMENTS:
pip_args.append( req )
print('Installing requirements: ' + str(REQUIREMENTS))
pip.main(initial_args = pip_args)
# do it again
from setuptools import find_packages
from distutils.core import setup
from Cython.Distutils import build_ext as cython_build
import sortedcollection
@frgomes
Copy link
Author

frgomes commented Feb 23, 2015

Installing packages programmatically in your setup.py :: In general, you don't need to do this, since function setup accepts a list of requirements as part of key install_requires. But, in certain circumstances, in particular if you are writing extensions to distutils, you may find useful to make sure that your setup.py has knowledge about everything it needs to install whatever requirements it may be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment