0

I am using oct2py to call a octave function in my python code. The file is saved as .py file in the htdocs folder.

#!/usr/bin/python
import cgi
import oct2py
from oct2py import octave
print('Content-type:text/html\r\n\r\n')
print('<!DOCTYPE html>')
firnum='23'
secnum='33'
octave.addpath('/Applications/XAMPP/xamppfiles/htdocs/mypython/Octavemfiles/')
firnum=int(firnum)
secnum=int(secnum)
answer=octave.mymultfunct(firnum,secnum)
print(answer)

The code works well when executing from the terminal and gives the answer. But when I call it through the web, the oct2py gives an error stating

OSError: Octave Executable not found, please add to path or set"OCTAVE_EXECUTABLE" environment. 

Please suggest a way out so I can call the function from octave. The octave function is just multiplying the numbers.

Suever
  • 64,497
  • 14
  • 82
  • 101
amathur
  • 11
  • 2
  • 1
    The error message tells you two possible ways to solve the problem. Have you tried any of them? – ForceBru Nov 20 '16 at 16:41
  • The webserver presumably does not run with the same environmental variables initialised as your local terminal. If you are unable to define OCTAVE_EXECUTABLE at the point of launching the webserver, perhaps you will be able to define it within python before importing oct2py itself (see: http://stackoverflow.com/questions/5971312/how-to-set-environment-variables-in-python for an example of setting environment variables from within python) – Tasos Papastylianou Nov 20 '16 at 20:10
  • I am new to this, how do I add path for Octave. The program doesn't execute the line ' from oct2py import octave'. Thanks – amathur Nov 21 '16 at 11:04
  • @amathur have you tried importing via python as I said above? it would look something like `os.environ["OCTAVE_EXECUTABLE"] = "/path/to/your/octave/executable"` (assuming that your webserver has permission to access that path) – Tasos Papastylianou Nov 22 '16 at 12:30
  • Is the package 'oct2py' installed in your runtime enviroment? (From the webserver) – Nils Aug 14 '17 at 13:51

1 Answers1

0

In Linux distribution: command : sudo pip install oct2py Error:

import oct2py Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/oct2py/init.py", line 38, in octave = Oct2Py() File "/usr/local/lib/python2.7/dist-packages/oct2py/core.py", line 73, in init self.restart() File "/usr/local/lib/python2.7/dist-packages/oct2py/core.py", line 508, in restart logger=self.logger) File "/usr/local/lib/python2.7/dist-packages/octave_kernel/kernel.py", line 157, in init self.executable = self._get_executable() File "/usr/local/lib/python2.7/dist-packages/octave_kernel/kernel.py", line 432, in _get_executable raise OSError(msg) OSError: Octave Executable not found, please add to path or set"OCTAVE_EXECUTABLE" environment variable

Solution Please install octave using : command : sudo apt-get install octave

ubuntu@host:~$ python Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import oct2py

yuki
  • 1