emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Troublesome python block
@ 2017-10-11 15:25 Roger Mason
  2017-10-11 16:13 ` Kyle Meyer
  2017-10-11 16:35 ` Kaushal Modi
  0 siblings, 2 replies; 3+ messages in thread
From: Roger Mason @ 2017-10-11 15:25 UTC (permalink / raw)
  To: Org-Mode

hello,

This python block:

#+BEGIN_SRC python :session true :results output
  import numpy as np
  from ase import Atoms
  from ase.calculators.gulp import GULP, Conditions

  quartz = Atoms(symbols='Si3O6', pbc=np.array([True,True,True], dtype=bool),
           cell=np.array([[4.916, 0.0, 0.0], [-2.4579999999999993, 4.257380885004301, 0.0], [0.0, 0.0, 5.4054]]),
	   positions=np.array([[ 2.3016712,   0.,      1.80161982],
                      [-1.1508356, 1.99330573, 3.60341982],
                      [ 1.3071644, 2.26407515, 5.40521982],
                      [ 1.3767258, 1.13288905, 1.15189074],
                      [ 3.2465264, 0.62583499, 2.95369074],
                      [ 2.7507478, 2.49865684, 4.75549074],
                      [ 0.2927478, 1.75872404, 4.25350926],
                      [-1.0812742, 3.12449183, 2.45170926],
                      [ 0.7885264, 3.63154589, 0.64990926]]))
#+END_SRC

produces this output:

#+RESULTS:
#+begin_example
Python 2.7.13 (default, Jul  2 2017, 01:20:25) 
[GCC 4.2.1 Compatible FreeBSD Clang 3.4.1 (tags/RELEASE_34/dot1-final 208032)] on freebsd10
Type "help", "copyright", "credits" or "license" for more information.
python.el: native completion setup loaded
and
as
assert
break
class
continue
def
del
elif
else
....[SNIPPED]....
AttributeError
OverflowError

0__dummy_completion__  1__dummy_completion__
#+end_example

The same python script produces no errors in a python interpreter
started from the command line and it reports no errors when run as
'python twaddle.py'.

Any help in debugging this will be much appreciated.

Roger

Org mode version 9.0.3 (release_9.0.3-170-gfed1cf @
/home/rmason/.emacs.d/org-git/org-mode/lisp/)
GNU Emacs 25.2.1 (i386-portbld-freebsd10.3, GTK+ Version 3.22.15) of 2017-07-03
Python 2.7.13 (default, Jul  2 2017, 01:20:25) 
[GCC 4.2.1 Compatible FreeBSD Clang 3.4.1 (tags/RELEASE_34/dot1-final 208032)] on freebsd10

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Troublesome python block
  2017-10-11 15:25 Troublesome python block Roger Mason
@ 2017-10-11 16:13 ` Kyle Meyer
  2017-10-11 16:35 ` Kaushal Modi
  1 sibling, 0 replies; 3+ messages in thread
From: Kyle Meyer @ 2017-10-11 16:13 UTC (permalink / raw)
  To: Roger Mason, Org-Mode

Hello,

Roger Mason <rmason@mun.ca> writes:

> This python block:

[...]

> produces this output:
>
> #+RESULTS:
> #+begin_example
> Python 2.7.13 (default, Jul  2 2017, 01:20:25) 
> [GCC 4.2.1 Compatible FreeBSD Clang 3.4.1 (tags/RELEASE_34/dot1-final 208032)] on freebsd10
> Type "help", "copyright", "credits" or "license" for more information.
> python.el: native completion setup loaded

[...]

> Any help in debugging this will be much appreciated.

ob-python sessions have been broken to some degree for quite some time.
See, e.g., https://lists.gnu.org/archive/html/emacs-orgmode/2015-03/msg00540.html

I dropped my attempt to fix it because 1) I was still having trouble
getting a complete understanding of what the issue was and 2) I didn't
have the motivation to spend time digging deeper because I don't use
ob-python (and in general am not a heavy Org-Babel user).  Perhaps you
or some other ob-python user could help make ob-python sessions more
robust?

In the meantime, you could try ob-ipython (https://github.com/gregsexton/ob-ipython).
Looking at the README, it sounds like ob-python's problems were one of
the author's motivations for writing the library.

-- 
Kyle

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Troublesome python block
  2017-10-11 15:25 Troublesome python block Roger Mason
  2017-10-11 16:13 ` Kyle Meyer
@ 2017-10-11 16:35 ` Kaushal Modi
  1 sibling, 0 replies; 3+ messages in thread
From: Kaushal Modi @ 2017-10-11 16:35 UTC (permalink / raw)
  To: Roger Mason, Org-Mode

[-- Attachment #1: Type: text/plain, Size: 4035 bytes --]

On Wed, Oct 11, 2017 at 11:26 AM Roger Mason <rmason@mun.ca> wrote:

> hello,
>
> This python block:
>
> #+BEGIN_SRC python :session true :results output
>   import numpy as np
>   from ase import Atoms
>   from ase.calculators.gulp import GULP, Conditions
>
>   quartz = Atoms(symbols='Si3O6', pbc=np.array([True,True,True],
> dtype=bool),
>            cell=np.array([[4.916, 0.0, 0.0], [-2.4579999999999993,
> 4.257380885004301, 0.0], [0.0, 0.0, 5.4054]]),
>            positions=np.array([[ 2.3016712,   0.,      1.80161982],
>                       [-1.1508356, 1.99330573, 3.60341982],
>                       [ 1.3071644, 2.26407515, 5.40521982],
>                       [ 1.3767258, 1.13288905, 1.15189074],
>                       [ 3.2465264, 0.62583499, 2.95369074],
>                       [ 2.7507478, 2.49865684, 4.75549074],
>                       [ 0.2927478, 1.75872404, 4.25350926],
>                       [-1.0812742, 3.12449183, 2.45170926],
>                       [ 0.7885264, 3.63154589, 0.64990926]]))
> #+END_SRC
>
> produces this output:
>
> #+RESULTS:
> #+begin_example
> Python 2.7.13 (default, Jul  2 2017, 01:20:25)
> [GCC 4.2.1 Compatible FreeBSD Clang 3.4.1 (tags/RELEASE_34/dot1-final
> 208032)] on freebsd10
> Type "help", "copyright", "credits" or "license" for more information.
> python.el: native completion setup loaded
> and
> as
> assert
> break
> class
> continue
> def
> del
> elif
> else
> ....[SNIPPED]....
> AttributeError
> OverflowError
>
> 0__dummy_completion__  1__dummy_completion__
> #+end_example
>
> The same python script produces no errors in a python interpreter
> started from the command line and it reports no errors when run as
> 'python twaddle.py'.
>
> Any help in debugging this will be much appreciated.
>
> Roger
>
> Org mode version 9.0.3 (release_9.0.3-170-gfed1cf @
> /home/rmason/.emacs.d/org-git/org-mode/lisp/)
> GNU Emacs 25.2.1 (i386-portbld-freebsd10.3, GTK+ Version 3.22.15) of
> 2017-07-03
> Python 2.7.13 (default, Jul  2 2017, 01:20:25)
> [GCC 4.2.1 Compatible FreeBSD Clang 3.4.1 (tags/RELEASE_34/dot1-final
> 208032)] on freebsd10
>

I cannot recreate that, though I am on different versions for everything:

- Emacs: 26.0.60 built from emacs-26 branch <-- This might be what actually
matters as I know that there were quite a few python.el commits in this
branch (
http://git.savannah.gnu.org/cgit/emacs.git/log/?h=emacs-26&qt=grep&q=python
 ).
- Org: built from Org master branch
- Python 3.6.2

I haven't used numpy or ase/scipy, so after:

> pip3 install --user numpy
> pip3 install --user scipy

I get:

#+PROPERTY: header-args:python :exports both :results output
#+BEGIN_SRC python
import numpy as np
from ase import Atoms
from ase.calculators.gulp import GULP, Conditions

quartz = Atoms(symbols='Si3O6', pbc=np.array([True,True,True], dtype=bool),
         cell=np.array([[4.916, 0.0, 0.0], [-2.4579999999999993,
4.257380885004301, 0.0], [0.0, 0.0, 5.4054]]),
         positions=np.array([[ 2.3016712,   0.,      1.80161982],
                    [-1.1508356, 1.99330573, 3.60341982],
                    [ 1.3071644, 2.26407515, 5.40521982],
                    [ 1.3767258, 1.13288905, 1.15189074],
                    [ 3.2465264, 0.62583499, 2.95369074],
                    [ 2.7507478, 2.49865684, 4.75549074],
                    [ 0.2927478, 1.75872404, 4.25350926],
                    [-1.0812742, 3.12449183, 2.45170926],
                    [ 0.7885264, 3.63154589, 0.64990926]]))
print(quartz)
#+END_SRC

#+RESULTS:
: Atoms(symbols='Si3O6', pbc=True, cell=[[4.916, 0.0, 0.0],
[-2.4579999999999993, 4.257380885004301, 0.0], [0.0, 0.0, 5.4054]])


Is that what you expected in the RESULTS?

Here is my relatively simply python setup where I default the interpreter
to python3:
https://github.com/kaushalmodi/.emacs.d/blob/master/setup-files/setup-python.el

and my minimal ob-python setup:

(use-package ob-python
  :defer t
  :config
  (progn
    (setq org-babel-python-command "python3"))) ;Default to python 3.x

-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 5657 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-11 16:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-11 15:25 Troublesome python block Roger Mason
2017-10-11 16:13 ` Kyle Meyer
2017-10-11 16:35 ` Kaushal Modi

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).