<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 15, 2013 at 9:39 AM, Paul Moore <span dir="ltr"><<a href="mailto:p.f.moore@gmail.com" target="_blank">p.f.moore@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm looking at the possibility of replacing the current setuptools entry point based pip executables with Python scripts. The biggest problem is that a script "pip.py" shadows the pip package, making "import pip" fail.<div>


<br></div><div>I can get round this by deleting sys.path[0] (the location of the currently running script) but how robust is that? Are there any corner cases where it would break? Or alternatively, is there a better way to do this rather than messing directly with sys.path? I suspect this is a fairly common question, but my Google-fu is failing me :-(</div>


<div><br></div><div>Sorry, I know this is a basic Python coding question - in my defence, it's for something related to the current pip discussions :-)</div><span class="HOEnZb"><font color="#888888"><div><span style="color:rgb(34,34,34)"></span></div>

</font></span></div></blockquote><div><br></div><div>As long as you make sure that sys.path[0] is actually the script location then it will work (other things like .pth files, PYTHONSTARTUP, etc. could have changed things before your script started execution). But realize that a) in Python 3.3 the scripts location will be ./pip.py, not just pip.py, and b) if I get my way all paths will be absolute for __file__, so you will have to just associate '' with os.getcwd() Â and then search for the proper directory on sys.path.</div>

</div></div></div>