[Distutils] Setuptools/Distribute - using from a "non-installed" location

Paul Moore p.f.moore at gmail.com
Thu Feb 28 21:26:08 CET 2013

For some scripts I am writing, I want to be able to run a package's
setup.py using subprocess.check_call(). However, the python
installation I'm using may not have setuptools/distribute installed,
and yet I want to correctly process setup.py files which rely on
setuptools. Is there any way of setting things up so that the Python
subprocess can use a local, non-installed, copy of setuptools or
distribute for the setup.py run? I've tried setting PYTHONPATH, but
that doesn't seem to work - probably because directories on PYTHONPATH
do not have .pth files processed.

To clarify, what I'm doing is:

here = os.path.abspath(os.path.dirname(__file__))
# setuptools is available in os.path.join(here, 'setuptools')
# setuptools.pth and easy-install.pth are in here

os.environ[PYTHONPATH] = here # this doesn't work
setup_py = <the setup.py file>
setup_dir = os.path.abspath(os.path.dirname(setup_py))
subprocess.check_call([sys.executable, 'setup.py', 'install'] +
special_install_options, cwd=setup_dir)

The point of this is that I want to write a script to build wheels
from sdists, but I don't want to require the user to install
setuptools just for the build step.

Does anyone have any suggestions?

More information about the Distutils-SIG mailing list