Changeset 9455


Ignore:
Timestamp:
Nov 30, 2014 10:01:18 AM (4 years ago)
Author:
wehart
Message:

Various fixes to get pyomo_install working on
a "new" Mac. Principally, this involved more
carefully checking that pip was installed and setting
the PYTHONPATH environment to use the pip installation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyomo/trunk/scripts/pyomo_install

    r9420 r9455  
    3131    pyomo_install_tempdir = None
    3232keep_tempdir = False
    33 user_path = os.path.join(os.environ['PYOMO_INSTALL_TEMPDIR'], 'usr')
    34 os.environ['PYTHONUSERBASE'] = user_path
    35 site.USER_BASE = user_path
    3633
    3734#
     
    5552def call_subprocess(cmd, options, stdout=False):
    5653    env = os.environ.copy()
     54    #
     55    # The next two tests are a hack.  These environment variables somehow influence the way that pip
     56    # behaves.
     57    #
     58    if '_':
     59        del env['_']
     60    if '__PYVENV_LAUNCHER__' in env:
     61        del env['__PYVENV_LAUNCHER__']
     62    #
    5763    cwd = os.getcwd()
    5864    if options.verbose or stdout:
     
    233239        help='Install Pyomo in a virtual environment that is created in the VENV directory')
    234240    parser.add_option(
     241        '-t', '--tempdir',
     242        dest='tempdir',
     243        default=None,
     244        help='Specify the temporary directory used to install temporary python packages')
     245    parser.add_option(
    235246        '-u', '--user',
    236247        dest='user',
     
    283294        raise SystemExit(1)
    284295    #
     296    # Override the default tempdir
     297    #
     298    if options.tempdir:
     299        global pyomo_install_tempdir
     300        rmtree(pyomo_install_tempdir)
     301        os.mkdir(options.tempdir)
     302        pyomo_install_tempdir = os.path.abspath(options.tempdir)
     303        os.environ['PYOMO_INSTALL_TEMPDIR'] = pyomo_install_tempdir
     304    #
    285305    # Find the version of Python that will be used to install Pyomo
    286306    #
     
    312332            print("\n************* Installing pip *******************")
    313333        install_pip(upgrade=options.zipfile is None, user=False, quiet=not options.verbose)
    314     pip = os.path.abspath(os.path.join(sys.exec_prefix, 'bin', 'pip'))
     334    pip = os.path.abspath(os.path.join(pyomo_install_tempdir, sys.exec_prefix[1:], 'bin', 'pip'))
    315335    if not os.path.exists(pip):
    316         pip = os.path.abspath(os.path.join(site.USER_BASE, 'bin', 'pip'))
     336        print("ERROR: Problem installing pip: "+pip+" "+str(pyomo_install_tempdir))
     337        raise SystemExit(1)
     338    else:
     339        tmp = []
     340        import site
     341        for dir_ in site.getsitepackages():
     342            if dir_.startswith(sys.exec_prefix):
     343                tmp.append( os.path.abspath(os.path.join(pyomo_install_tempdir, dir_[1:])) )
     344        os.environ['PYTHONPATH'] = os.pathsep.join( tmp )
     345        #print(os.environ['PYTHONPATH'])
    317346    #
    318347    python_dir = os.path.abspath(sys.exec_prefix)
     
    336365        call_subprocess([pip, 'install', '-v', '--target=%s' % pyomo_install_tempdir,'pyutilib.virtualenv'], options)
    337366        vpy_install = os.path.join(pyomo_install_tempdir, 'pyutilib', 'virtualenv', 'vpy_install.py')
     367        del os.environ['PYTHONPATH']
    338368        #
    339369        # Run vpy_install to install the Pyomo trunk in a virtual environment
     
    392422                    #
    393423                    pip = os.path.join(os.path.abspath(options.venv), 'bin', 'pip')
     424                    del os.environ['PYTHONPATH']
    394425                else:
    395426                    #
     
    410441                    #
    411442                    pip = os.path.join(os.path.abspath(options.venv), 'bin', 'pip')
     443                    del os.environ['PYTHONPATH']
    412444            else:
    413445                #
     
    433465                #
    434466                pip = os.path.join(os.path.abspath(options.venv), 'bin', 'pip')
     467                del os.environ['PYTHONPATH']
    435468            python_dir = os.path.abspath(options.venv)
    436469        if options.zipfile:
Note: See TracChangeset for help on using the changeset viewer.