Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error trying to import octave in Anaconda Spyder using "from oct2py import octave" #303

Open
HamidKarimi-Rouzbahani opened this issue Oct 20, 2023 · 8 comments

Comments

@HamidKarimi-Rouzbahani
Copy link

HamidKarimi-Rouzbahani commented Oct 20, 2023

Hi there,

I am trying to import octave in Anaconda Spyder using this command:

from oct2py import octave

However, it gives an error and says:

cannot import name 'octave' from 'oct2py' (C:\ ...\ ...\Anaconda3\envs\pyspi\lib\site-packages\oct2py_init_.py)

my oct2py is a version 5.6.0 and I am using Python 3.9.0 on a Windows 10 machine.

Can you help me with this issue?

Thanks,
Hamid

@blink1073
Copy link
Owner

Hi @HamidKarimi-Rouzbahani, what is the error that is printed? It his coming from this line.

@HamidKarimi-Rouzbahani
Copy link
Author

HamidKarimi-Rouzbahani commented Oct 20, 2023

Hi @blink1073,

Thanks for getting back to me.

The error is as above:

ImportError: cannot import name 'octave' from 'oct2py' (C:\Users\99021\Anaconda3\envs\pyspi\lib\site-packages\oct2py\ init.py)

Please note that it drops the double underlines before and after init when I paste the error here.

I am not sure which line of init it comes from. Sorry, I am not super familiar with Python.

Is there any more information that can help you?

I am trying to use the pyspi toolbox, which seems to use some matlab codes and therefore needs octave. So, it calls oct2py to load octave but seems to fail. I have installed GNU octave from here: https://octave.org/download

Thanks

@blink1073
Copy link
Owner

Hmm, perhaps this command will give us a better answer. python -m octave_kernel.check. oct2py uses the octave_kernel to interact with Octave.

@HamidKarimi-Rouzbahani
Copy link
Author

HamidKarimi-Rouzbahani commented Oct 25, 2023

Command Prompt returns this error:

C:\Program Files\Python\Python39\python.exe: Error while finding module specification for 'octave_kernel.check.' (ModuleNotFoundError: No module named 'octave_kernel')

Would it be possible to drop a few lines here about how to install octave and load it through oct2py in Spyder? Maybe if I understand how it is to be done, I can manage to fix the problem somehow.

@blink1073
Copy link
Owner

This looks like a multiple-pythons issue. I'd recommend asking for help from the spyder folks, I haven't used spyder in many years.

@zhrli
Copy link

zhrli commented Nov 26, 2023

Hmm, perhaps this command will give us a better answer. python -m octave_kernel.check. oct2py uses the octave_kernel to interact with Octave.

I have the same problem when I import octave

root@62ec78395647:/home# python3 -m octave_kernel.check
Octave kernel v0.35.1
Metakernel v0.30.1
Python v3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Python path: /usr/bin/python3

Connecting to Octave...
Octave connection established
Timeout exceeded.
<pexpect.pty_spawn.spawn object at 0x7f7bab7b8610>
command: /usr/bin/octave
args: [b'/usr/bin/octave', b'--interactive', b'--quiet', b'--no-init-file']
buffer (last 100 chars): ''
before (last 100 chars): ''
after: <class 'pexpect.exceptions.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 306
child_fd: 6
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
0: re.compile('octave.*>')

@zhrli
Copy link

zhrli commented Nov 26, 2023

Hmm, perhaps this command will give us a better answer. python -m octave_kernel.check. oct2py uses the octave_kernel to interact with Octave.

And I ran this :

import oct2py
dir(oct2py)
['Cell', 'Oct2Py', 'Oct2PyError', 'Struct', 'StructArray', 'all', 'builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'path', 'spec', 'version', 'demo', 'get_log', 'kill_octave', 'speed_check', 'thread_check']
dir(oct2py.Oct2Py)
['class', 'del', 'delattr', 'dict', 'dir', 'doc', 'enter', 'eq', 'exit', 'format', 'ge', 'getattr', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'le', 'lt', 'module', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', '_exist', '_feval', '_get_doc', '_get_function_ptr', '_get_max_nout', '_get_user_class', '_handle_stdin', '_isobject', '_parse_error', '_print_doc', 'eval', 'exit', 'extract_figures', 'feval', 'get_pointer', 'logger', 'pull', 'push', 'restart']
oc = Oct2Py()
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/oct2py/core.py", line 563, in restart
self._engine = OctaveEngine(stdin_handler=self._handle_stdin, logger=self.logger)
File "/usr/local/lib/python3.10/dist-packages/octave_kernel/kernel.py", line 185, in init
self.repl = self._create_repl()
File "/usr/local/lib/python3.10/dist-packages/octave_kernel/kernel.py", line 416, in _create_repl
repl = REPLWrapper(cmd, orig_prompt, change_prompt,
File "/usr/local/lib/python3.10/dist-packages/metakernel/replwrap.py", line 88, in init
self.set_prompt(prompt_regex,
File "/usr/local/lib/python3.10/dist-packages/metakernel/replwrap.py", line 112, in set_prompt
self.child.expect(prompt_regex)
File "/usr/local/lib/python3.10/dist-packages/pexpect/spawnbase.py", line 343, in expect
return self.expect_list(compiled_pattern_list,
File "/usr/local/lib/python3.10/dist-packages/pexpect/spawnbase.py", line 372, in expect_list
return exp.expect_loop(timeout)
File "/usr/local/lib/python3.10/dist-packages/pexpect/expect.py", line 181, in expect_loop
return self.timeout(e)
File "/usr/local/lib/python3.10/dist-packages/pexpect/expect.py", line 144, in timeout
raise exc
pexpect.exceptions.TIMEOUT: Timeout exceeded.
<pexpect.pty_spawn.spawn object at 0x7f42fc42dba0>
command: /usr/bin/octave
args: [b'/usr/bin/octave', b'--interactive', b'--quiet', b'--no-init-file']
buffer (last 100 chars): ''
before (last 100 chars): ''
after: <class 'pexpect.exceptions.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 398
child_fd: 9
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
0: re.compile('octave.*>')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.10/dist-packages/oct2py/core.py", line 87, in init
self.restart()
File "/usr/local/lib/python3.10/dist-packages/oct2py/core.py", line 565, in restart
raise Oct2PyError(str(e))
oct2py.utils.Oct2PyError: Timeout exceeded.
<pexpect.pty_spawn.spawn object at 0x7f42fc42dba0>
command: /usr/bin/octave
args: [b'/usr/bin/octave', b'--interactive', b'--quiet', b'--no-init-file']
buffer (last 100 chars): ''
before (last 100 chars): ''
after: <class 'pexpect.exceptions.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 398
child_fd: 9
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
0: re.compile('octave.*>')

@17Reset
Copy link

17Reset commented Jul 1, 2024

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants