Junnan Zhu
Junnan Zhu

Reputation: 87

how to set python env in org mode

When I write some python code in emacs org-mode, how can I set the python env to a specific env. I use the code as follow but it didn't work.

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

Upvotes: 3

Views: 3234

Answers (2)

rortms
rortms

Reputation: 41

I also needed org-mode to run python from one of my anaconda environments. You can set the emacs variable, python-shell-virtualenv-root, to the anaconda environment's path. That is;

M-x customize-variable RET

python-shell-virtualenv-root RET

Click on the Value Menu button where you can then type in the box

String:/PATH/TO/VIRTUALENV

That solved it for me.

EDIT: I failed to mention the above was tested only on emacs 25.2 Additionally, I now realize the solution works only in session code blocks. If a session is not specified, then the python code is run with the default, system-wide, Python installation.

Upvotes: 2

brittAnderson
brittAnderson

Reputation: 1473

You could go to the scratch buffer and execute (setq org-babel-python-command "python2")

Then in an org file try

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

And should get something like:

#+RESULTS:
: 2.7.13

If that works then add it to your init file.

Upvotes: 3

Related Questions