<h2>把茱莉亚放在一个IPython笔记本里</h2>
<p><br/></p>
<h2>黑客</h2>
<p>为了在IPython笔记本中运行Julia片段(或<em>其他</em>语言),我只需将字符串<code>'julia'</code>附加到<code>_script_magics_default</code>方法中<code>ScriptMagics</code>类的<code>default</code></strong>列表中:</p>
<ul>
<li><code>/usr/lib/python3.4/site-packages/IPython/core/magics/script.py</code>或</li>
<li><code>/usr/lib/python2.7/site-packages/IPython/core/magics/script.py</code>。</li>
</ul>
<h3>示例:</h3>
<pre><code># like this:
defaults = [
'sh',
'bash',
'perl',
'ruby',
'python',
'python2',
'python3',
'pypy',
'julia', # add your own magic
]
</code></pre>
<ul>
<li><a href="http://nbviewer.ipython.org/urls/gist.githubusercontent.com/Ismael-VC/ae10c11d535f6741d8be/raw/4fa2f4c40fa7acc8c6e440ef34afd148b7c3f7d2/julia_magic.ipynb" rel="noreferrer">Example notebook</a>(使用Python3)</li>
</ul>
<p><img src="https://i.stack.imgur.com/Fwu6C.png" alt="IPython *Julia magic*"/></p>
<h2>朱莉娅魔术(双向)</h2>
<p>要使用<code>%load_ext julia.magic</code>,您需要在这里运行<code>setup.py</code>:</p>
<p><strong><em>更新(2014年4月9日)</em></strong>:已将<code>setup.py</code>文件移到pyjulia.jl:</p>
<ul>
<li><a href="https://github.com/JuliaLang/pyjulia" rel="noreferrer">https://github.com/JuliaLang/pyjulia</a></li>
</ul>
<p><罢工>
当<code>Pkg.add("IJulia")</code>克隆文件系统中的repo时,您会得到这样的结果:</strike></p>
<pre><code>cd ~/.julia/v0.3/IJulia/python/
sudo python2 setup.py install
</code></pre>
<p/>
<p>目前这只适用于<em>Python2</em>中的我。Python3抱怨:</p>
<pre><code>ImportError: No module named 'core'
</code></pre>
<p>当我试图加载扩展时,却没有抱怨就安装了。</p>
<p>安装之后,您还可以从Python2内部执行此操作:</p>
<pre><code>from julia import Julia
j = Julia()
arr = j.run('[1:10]')
type(arr) # numpy.ndarray
</code></pre>
<ul>
<li><a href="http://blog.leahhanson.us/julia-calling-python-calling-julia.html" rel="noreferrer">http://blog.leahhanson.us/julia-calling-python-calling-julia.html</a></li>
</ul>
<h2>从系统运行脚本</h2>
<p>在笔记本单元格中使用<em>shell</em>模式语法:</p>
<pre><code>!julia my_script.jl
</code></pre>
<p><br/></p>
<hr/>
<h2>在IJulia笔记本中运行Python</h2>
<p><br/></p>
<h2>使用PyCall</h2>
<p>在您想要的上下文中运行python代码并不是真正的<em>,但是您也可以使用Julia中的python库:</p>
<pre><code>using PyCall
@pyimport math
println(math.pi)
</code></pre>
<ul>
<li><a href="https://github.com/stevengj/PyCall.jl" rel="noreferrer">https://github.com/stevengj/PyCall.jl</a></li>
</ul>
<h2>从系统运行脚本</h2>
<p>在笔记本单元格中使用<em>shell</em>模式语法:</p>
<pre><code>;python my_script.py
</code></pre>
<ul>
<li><a href="http://julia.readthedocs.org/en/latest/manual/interacting-with-julia/?highlight=shell#shell-mode" rel="noreferrer">http://julia.readthedocs.org/en/latest/manual/interacting-with-julia/?highlight=shell#shell-mode</a></li>
</ul>