简体   繁体   中英

oct2py in Anaconda/Spyder not recognizing octave

Windows7

Anaconda/python ver 3.4

Octave ver 4.0.3

OCTAVE_EXECUTABLE = C:\\Users\\Heather\\Octave-4.0.3\\bin

Hi all,

I've been working a few days on trying to get oct2py working in Anaconda using Spyder. I was wondering if anyone could tell me the correct way to get it to work in Spyder on a windows machine? Basic setup maybe or maybe I'm using the wrong packages?

So far I've installed the oct2py package per the Anaconda Cloud using:

conda install -c conda-forge oct2py=3.5.9

In all the documentation for oct2py it mentioned needing to have Octave downloaded in order for oct2py to work. So from this page pypi.python.org/pypi/oct2py, it mentioned getting Octave from sourceforge at

https://sourceforge.net/projects/octave/files/Octave%20Windows%20binaries/ .

I downloaded the Octave 3.6.4 from there and a friend helped me to get the OCTAVE_EXECUTABLE in my environment variables pointing towards it. At this point I was able to type 'octave' in a command line and it would bring up an octave instance, but Spyder would never recognize I had octave installed.

ergo:

from oct2py import octave

Error: cannot import name octave

At this point I realized the sourceforge Octave said it was a supplemental package, so I uninstalled the Octave 3.6.4 and installed Octave 4.0.3 from http://www.gnu.org/software/octave/ for windows. Now Octave opens nicely when I click on the application but the command line does not recognize the term 'octave' which I feel is a step back. I looked at my env variables again and the new path for Octave was present in the system variables and I updated the OCTAVE_EXECUTABLE to point to the new version of Octave (with no whitespaces in the directory). But my computer even after full shutdown and restarts does not recognize 'octave' in the command line and Spyder still does not see that I have octave when I try running oct2py.Oct2Py().

So after all this I was wondering if anyone has gotten oct2py to work in Anaconda but especially using Spyder? How so? I am trying to get my python script to open and use a .m file to perform a function and output a matrix that will be used further in the script for computation. However if I can't even get it to recognize octave then I don't know how I'll get this finished.

Sample of code:

from oct2py import Oct2Py
filename = 'filename'
oc = Oct2Py()
eph_matrix = oc.read_eph(filename)
print(eph_matrix) #nx25 matrix

I am hopeful if I can just get python to recognize Octave that I can get past the import line.

Any help would be very appreciated.

The OCTAVE_EXECUTABLE or OCTAVE environment variables should point directly to the executable and not the folder that contains the executable. So you'll likely want to set it to

OCTAVE_EXECUTABLE = C:\Users\Heather\Octave-4.0.3\bin\octave-cli.exe

Another option is to provide the executable as the first input to Oct2Py .

from oct2py import Oct2Py
octave = Oct2Py('C:\Users\Heather\Octave-4.0.3\bin\octave-cli.exe')

Also, if you want to be able to run it from the Windows command prompt, you will want to add the folder containing the executables ( 'C:\\Users\\Heather\\Octave-4.0.3\\bin' ) to the PATH environment variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM