Last active
August 27, 2017 17:07
-
-
Save frgomes/6140463 to your computer and use it in GitHub Desktop.
Python - Installing packages programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 keyinstall_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.