<p>经过一些痛苦的尝试,我成功地在代码中使用了<code>import clr</code>。在</p>
<p>首先,我需要使用正确的二进制文件,为了实现这一点,我使用了pythonnet/pythonnet包git的最新开发源代码。在</p>
<p>您可以尝试:<code>$ sudo pip install pre pythonnet</code>,下载并安装最新的开发源代码。但请记住,有一些额外的,所以我附加了特拉维斯的建设细节</p>
<pre><code>system_info
Build language: python
Operating System: Ubuntu 12.04 LTS
$ python version
Python 2.7.9
$ pip version
pip 6.0.7 from /home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages (python 2.7)
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe"
$ sudo apt-get -qq install mono-devel mono-gmcs mono-xbuild nunit-console
$ sudo mozroots import machine sync
$ yes | sudo certmgr -ssl -m https://go.microsoft.com
$ yes | sudo certmgr -ssl -m https://nugetgallery.blob.core.windows.net
$ yes | sudo certmgr -ssl -m https://nuget.org
$ pip install six
</code></pre>
<p>现在通常安装带有pip的pythonnet应该可以成功执行,您可以尝试在python代码中调用import clr。就我个人而言,即使在这种情况下,它也失败了,尽管它没有错误地安装。原因是虽然我的python编译时没有启用共享,但是运行</p>
^{pr2}$
<p>返回1,但应返回0。在</p>
<p>所以我从git <a href="https://github.com/pythonnet/pythonnet" rel="nofollow">https://github.com/pythonnet/pythonnet</a>下载了最新的开发源代码</p>
<p>把它放进正确的文件夹后我编辑了设置.py设置变量
在执行之后,正在将共享库检查为0</p>
<pre><code>$ sudo python setup.py install
</code></pre>
<p>脚本安装成功,没有错误,我可以在python脚本中使用import clr。要确保一切正常运行,您可以运行:</p>
<pre><code>$ python src/tests/runtests.py
</code></pre>