[issue7744] Allow site.addsitedir insert to beginning of sys.path
Michael R. Bernstein
report at bugs.python.org
Tue Sep 9 14:26:48 CEST 2014
Michael R. Bernstein added the comment:
The lack of a left-append option for site.addsitedir(path), or an site.insertsitedir(index, path) (which is what I would consider a better solution), causes quite a few contortions on some hosted platforms, notably Google App Engine, for vendored packages.
I've been trying to find a more elegant solution than the following code, but haven't been able to find anything:
import os
import site
import sys
dirname = 'lib'
dirpath = os.path.join(os.path.dirname(__file__), dirname)
sys.path, remainder = sys.path[:1], sys.path[1:]
site.addsitedir(dirpath)
sys.path.extend(remainder)
And even asked on StackOverflow: http://stackoverflow.com/questions/25709832/what-is-the-cleanest-way-to-add-a-directory-of-third-party-packages-to-the-begin
Having a site.insertsitedir(index, path) available would make things so much simpler.
----------
nosy: +webmaven
versions: +Python 3.3, Python 3.4, Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7744>
_______________________________________
More information about the Python-bugs-list
mailing list