Chris's Wiki :: blog/python/AwkwardThirdPartyModules Commentshttps://utcc.utoronto.ca/~cks/space/blog/python/AwkwardThirdPartyModules?atomcommentsDWiki2010-09-16T04:04:40ZRecent comments in Chris's Wiki :: blog/python/AwkwardThirdPartyModules.From 129.96.120.11 on /blog/python/AwkwardThirdPartyModulestag:CSpace:blog/python/AwkwardThirdPartyModules:e482d6e21701cdab41678f34a6f3ce1ec82a3ed8From 129.96.120.11<div class="wikitext"><p>I use a proxy module in my source dir so i can dump 3rd party libs elsewhere. The "proxy" module is ridiculously simple:</p>
<p><em>examplelib.py</em></p>
<pre>
import os as _os # hide imports from the module's public namespace
execfile( _os.path.join( _os.path.dirname( __file__ ), '../ThirdParty/ExampleLib/examplelib.py' ) )
</pre>
<p>I put this proxy module in my source dir, so my code only needs to <code>import examplelib</code> without having to worry about <code>sys.path</code>. Note this supports relative paths, so you can have all your libs in source control and not worry about what your checkout path is. I haven't thought about how this would extend to importing a package though.</p>
<p>--Mark</p>
</div>2010-09-16T04:04:40ZBy Chris Siebenmann on /blog/python/AwkwardThirdPartyModulestag:CSpace:blog/python/AwkwardThirdPartyModules:ff91b7632e656c2f3dc59d3bd3c69d4a2009e7b8Chris Siebenmann<div class="wikitext"><p>The problem with .pth files in the system site-packages directory is that
if I do that, I'm effectively installing things system wide outside of
the OS's packaging system (with all of the problems that that implies).</p>
</div>2010-09-15T01:28:54ZFrom 80.2.144.138 on /blog/python/AwkwardThirdPartyModulestag:CSpace:blog/python/AwkwardThirdPartyModules:6f817ded32d0948904e82409e8941b9e68a11e28From 80.2.144.138<div class="wikitext"><p>How about just dropping a .pth file into your site-packages directory pointing at your central install location? No environment variables or wrappers, just one file per python install.</p>
</div>2010-09-15T00:01:33ZFrom 152.2.240.82 on /blog/python/AwkwardThirdPartyModulestag:CSpace:blog/python/AwkwardThirdPartyModules:2789cbb7682113e730fc511146fe4cd9f9c03669From 152.2.240.82<div class="wikitext"><p>How about virtualenv? You could define environments (or just a single "sysadmin" environment) for your scripts and use pip to manage the modules which would then live inside that environment. For cron if you call the virtual environment's python it gets all the trappings (e.g. modules) of that environment without a need to activate it.</p>
<pre>
/path/to/virtualenv/bin/python /path/to/script.py
</pre>
<p><a href="http://pypi.python.org/pypi/virtualenv">http://pypi.python.org/pypi/virtualenv</a></p>
<p><a href="http://www.doughellmann.com/projects/virtualenvwrapper/">http://www.doughellmann.com/projects/virtualenvwrapper/</a></p>
<p><a href="http://www.b-list.org/weblog/2008/dec/15/pip/">http://www.b-list.org/weblog/2008/dec/15/pip/</a></p>
<p>--Stephen Ball : <a href="http://xyzzyb.com">http://xyzzyb.com</a></p>
</div>2010-09-14T14:23:17Z