1

I have installled oct2py and I can import octave in shell interactive python3 mode.

lukas@lukas-VirtualBox:~$ python3
Python 3.5.2 (default, Sep 14 2017, 22:51:06) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from oct2py import octave
>>> octave.exp(1*2)
7.38905609893065
>>> 

But I cannot import octave in python3 script.

#!/usr/bin/env python3

import oct2py
from oct2py import octave

First line (import oct2py) is with no error. Second line produces error:

 File "/home/lukas/detection/octave/oct2py.py", line 4, in <module>
    from oct2py import octave
ImportError: cannot import name 'octave'

I have found topics here about this but nothing mentioned solved my problem. I have set octave to PATH:

export PATH=/usr/bin/octave:$PATH

No results It cannot import octave in script, just in the interactive mode.

I use Ubuntu 16.04.3 LTS, Octave 4.0.0, Python3, Scipy 0.17.0

zubro
  • 147
  • 7
  • have you set up an OCTAVE_EXECUTABLE env.variable as stated here http://blink1073.github.io/oct2py/source/installation.html ? is there a shell alias set up for `python` which creates that? – Tasos Papastylianou Oct 25 '17 at 17:52
  • Could you tell me more please how to set OCTAVE_EXECUTABLE and alias. I have found topics about alias but I am not sure what should I do. – zubro Oct 26 '17 at 08:38
  • you can see what aliases you have set by typing `alias` in your linux console. See if you have one for python. You can set an `OCTAVE_EXECUTABLE` environment variable same way as you did for `PATH`, e.g. `export OCTAVE_EXECUTABLE=/my/octave/installation/folder/bin` in the same session that you run your python script – Tasos Papastylianou Oct 26 '17 at 11:57
  • It should look like this: alias python3='python3,export OCTAVE_EXECUTABLE=/usr/bin/octave' or I have absolutely misunderstood you ? – zubro Oct 26 '17 at 12:17
  • Yes. Don't worry. Calling python interpreter from within a script may be calling something slightly different, because aliases are disabled inside scripts. I thought you may have an alias for python in your .bashrc file but you don't seem to. Are you sure the PATH you exported is correct? It seems to me like it's not correct. I would have expected something like `/usr/local/octave/bin` or `/opt/octave/bin` depending on where you installed it. Try the following: `import os; print(os.environ)` from both an interactive python3 terminal and from a script. Do they output exactly the same thing? – Tasos Papastylianou Oct 26 '17 at 13:53
  • Also, where exactly did you put that export statement? Is it in your .bashrc? – Tasos Papastylianou Oct 26 '17 at 13:54

0 Answers0