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

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

On 28 February 2013 20:30, Daniel Holth <dholth at gmail.com> wrote:
> On Thu, Feb 28, 2013 at 3:26 PM, Paul Moore <p.f.moore at gmail.com> wrote:
>> 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?
>> Paul
> Look at site.py, specifically site.addsitedir(sitedir, known_paths=None)

Sorry, I wasn't clear. I know about that, but I don't know how to set
up a site directory *before* starting the Python process. Thinking
about it, I guess I could do the addsitedir thing and then execfile
setup.py. Put all of that into a -c script. That's probably OK, just a
bit messy. Particularly as execfile is no longer a builtin.


More information about the Distutils-SIG mailing list