简体   繁体   中英

oct2py - cannot import name 'octave' when using spyder IDE

I have python 3.4.3 and octave 3.6.4 installed on my computer. I installed oct2py 3.30 through the command pip install oct2py and there were no errors shown, but when I try to run:

import numpy as np
from oct2py import octave

I get the following error:

  File "C:/Users/myname/myfile.py", line 2, in <module>
    from oct2py import octave

ImportError: cannot import name 'octave'

When looking for an answer I found a post from the creator explaining that when you import octave from oct2py you are importing a convenience instance of the Oct2Py class, so I tried the following:

from oct2py import Oct2Py

running this gave me the message:

octave not found.  Please see documentation at:
http://blink1073.github.io/oct2py/source/installation.html

but I've already done everything explained in the installation. Octave is in my path and if I open up the command prompt and type octave it will run octave.

edit: It turns out that if I run these commands in python from the command prompt they work, I only get the errors when running them from Spyder IDE. The only problem I can think of is there might be a file in Spyders working directory that conflicts with something, but I can't find anything when looking at the files.

I thought I should update that this is working now. The following time I started Spyder after restarting my computer I ran the same script unchanged and it worked. I presume that my computer just needed restarting after adding Octave to the path. I didn't originally think this was the case since after altering the path I could now run Octave from the command line without restarting, but nothing else changed since the script not working, restarting my computer, and the script working now.

I met the same problem using Python 2.7.10 and Octave 4.0.2 on Windows 8.1... I just modify the oct2py\\core.py file in line 697 by adding the following script. executable = executable + 'octave-cli' where the variable executable should be the OCTAVE_EXECUTABLE path. For example, "C:\\Octave\\Octave-4.0.2\\bin". Maybe is not a very good way, but it works.

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