[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Mixing Python2 and Python3 blocks in one file
From: |
John Kitchin |
Subject: |
Re: [O] Mixing Python2 and Python3 blocks in one file |
Date: |
Tue, 17 May 2016 11:37:46 -0400 |
User-agent: |
mu4e 0.9.16; emacs 25.1.50.1 |
You can hack this to work:
#+BEGIN_SRC emacs-lisp
(defun org-babel-execute:python2 (body params)
(let ((org-babel-python-command
"/Users/jkitchin/Library/Enthought/Canopy_64bit/User/bin/python2"))
(org-babel-execute:python body params)))
#+END_SRC
#+BEGIN_SRC python2
print 'Hello'
#+END_SRC
#+RESULTS:
: Hello
One issue though is no font-lock in the source block. I think it uses
the language to set the mode.
Karl Voit writes:
> Hi William
>
> * William Henney <address@hidden> wrote:
>>
>> On Sun, May 8, 2016 at 3:31 AM, Karl Voit <address@hidden> wrote:
>>
>> Python2 and Python3 are two different languages. Unfortunately,
>>> Org-mode only uses ~#+BEGIN_SRC python~ for both and uses
>>> python-shell-interpreter to choose/switch the compiler.
>>>
>>> Shouldn't Org-mode introduce ~#+BEGIN_SRC python2~ and ~#+BEGIN_SRC
>>> python3~ to solve this issue in a clean way?
>>>
>>> ~#+BEGIN_SRC python~ can still default to python2.
>>>
>> You can use the :python header argument to the source block, which allows
>> you to specify the path to the python interpreter:
>>
>> #+BEGIN_SRC python :python /Users/will/anaconda/envs/py27/bin/python
>
> Cool, I did not find this parameter yet.
>
> Is this undocumented? http://orgmode.org/org.html does not contain
> the string ":python:" and
> http://orgmode.org/org.html#Language_002dspecific-header-arguments
> also does not mention this parameter.
>
>> Also see original discussion at
>> https://lists.gnu.org/archive/html/emacs-orgmode/2014-04/msg01042.html
>
> Most interesting to me, thank you.
>
> With the parameter above as a workaround, I can accomplish the
> things I want to do for now. However, I still do think that Python2
> and Python3 as different languages demand different block
> identifiers.
>
> #+BEGIN_SRC python -> defaults to the default python interpreter
> #+BEGIN_SRC python2 -> uses Python2
> #+BEGIN_SRC python3 -> uses Python3
>
> Don't you think?
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
- [O] Mixing Python2 and Python3 blocks in one file, Karl Voit, 2016/05/08
- Re: [O] Mixing Python2 and Python3 blocks in one file, Karl Voit, 2016/05/08
- Re: [O] Mixing Python2 and Python3 blocks in one file, William Henney, 2016/05/17
- Re: [O] Mixing Python2 and Python3 blocks in one file, Karl Voit, 2016/05/17
- [O] Division of Org documentation: Org manual and Worg (was: Mixing Python2 and Python3 blocks in one file), Karl Voit, 2016/05/18
- Re: [O] Division of Org documentation: Org manual and Worg, Daniele Pizzolli, 2016/05/18
- Re: [O] Division of Org documentation: Org manual and Worg, Rasmus, 2016/05/18
- Re: [O] Division of Org documentation: Org manual and Worg, Daniele Pizzolli, 2016/05/18
- Re: [O] Division of Org documentation: Org manual and Worg, Rasmus, 2016/05/18
- Re: [O] Division of Org documentation: Org manual and Worg, Daniele Pizzolli, 2016/05/20
- Re: [O] Division of Org documentation: Org manual and Worg, Rasmus, 2016/05/20