擅长:python、mysql、java
<p>在edit中引用的解决方案使用xml.etree而不是lxml.etree并不是更好的方法,因为这些模块已经知道了<a href="http://lxml.de/1.3/compatibility.html" rel="noreferrer">incompatibilities</a>,而且主要是因为lxml肯定更为<a href="http://lxml.de/1.3/performance.html" rel="noreferrer">optimised</a>。</p>
<p>使用VirtualEnvironment是使环境变得干净的一个好方法:</p>
<pre><code>$ virtualenv myproject
$ cd myproject
$ ./bin/pip install lxml # Repeat this with other dependencies
[wait for download and compiling]
</code></pre>
<p>然后,使用<strong>/bin/python</strong>执行脚本。
这种方法的优点是:</p>
<ul>
<li>在系统和项目之间可以有不同版本的依赖关系</li>
<li>即使破坏了虚拟环境中的所有内容,也不会损害系统的其余部分</li>
<li>安装不需要根用户权限</li>
</ul>
<p>作为一个参考,实现这一点的一个更强大但稍微复杂的方法是使用<a href="http://www.buildout.org/" rel="noreferrer"><strong>buildout</strong></a>,但是如果您只想执行一个简单的单文件脚本,它看起来就像用火箭筒猎杀苍蝇。</p>