如何在org模式下设置python env

时间:2017-02-13 10:12:52

标签: python emacs org-mode

当我在emacs org-mode中编写一些python代码时,如何将python env设置为特定的env。我使用的代码如下,但它不起作用。

    #+BEGIN_SRC python :python /opt/local/bin/python2.7 :results output
    print "python 2"
    #+END_SRC

2 个答案:

答案 0 :(得分:2)

我还需要org-mode来从我的一个anaconda环境中运行python。您可以将emacs变量python-shell-virtualenv-root设置为anaconda环境的路径。那是;

M-x customize-variable RET

python-shell-virtualenv-root RET

点击“值菜单”按钮,然后在框中输入

的字符串:/PATH/TO/VIRTUALENV

这解决了我。

编辑: 我没有提到以上仅在emacs 25.2上测试过 此外,我现在意识到该解决方案仅适用于会话代码块。如果未指定会话,则使用默认的系统范围Python安装运行python代码。

答案 1 :(得分:0)

您可以转到临时缓冲区并执行(setq org-babel-python-command "python2")

然后在组织文件中尝试

#+BEGIN_SRC python
import platform
return platform.python_version()
#+END_SRC

应该得到类似的东西:

#+RESULTS:
: 2.7.13

如果可行,则将其添加到您的init文件中。