Open Ohmagar opened 1 year ago
I just saw that the code didn’t properly format here. (It is correctly formatted in my test - I just didn’t properly copy it.)
Hi, the problem is simple: there isn't a compiler on iOS. So Cython cannot work, since the way it works is:
Thank you. Could I „push“ you for my „another question“ at the end of this post? In regards to the change of the layout and havi to click on „open in…“ every time. Thanks in advance!
Ah yes. That change in layout is related to a change in Jupyter Notebooks themselves: we moved to Notebooks v7, the latest version. If you open the Settings app, you can change the default distribution from "Notebook" to "Nbclassic", and it will stay that way (until you want to change back).
Hi there!
I tried playing around with Cython within Carnets (since I use it when not coding with my iPad) and I am getting an error.
This is how I tried using it (I will use a „##C“ at the beginning and end of a cells for ease of reading):
C
%load_ext Cython
C
C
%%cython -a def geo_prog_cython(int n, int m): cdef int k cdef int summed for k in range(n): summed += m return summed
C
When I run the cell/s I get the following error: DistutilsExecError Traceback (most recent call last) File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/setuptools/_distutils/unixccompiler.py:185, in UnixCCompiler._compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts) 184 try: --> 185 self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs) 186 except DistutilsExecError as msg:
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/setuptools/_distutils/ccompiler.py:1041, in CCompiler.spawn(self, cmd, kwargs) 1040 def spawn(self, cmd, kwargs): -> 1041 spawn(cmd, dry_run=self.dry_run, **kwargs)
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/setuptools/_distutils/spawn.py:70, in spawn(cmd, search_path, verbose, dry_run, env) 69 cmd = cmd[0] ---> 70 raise DistutilsExecError( 71 "command {!r} failed with exit code {}".format(cmd, exitcode) 72 )
DistutilsExecError: command 'clang' failed with exit code 127
During handling of the above exception, another exception occurred:
CompileError Traceback (most recent call last) File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Build/IpythonMagic.py:349, in CythonMagics.cython(self, line, cell) 348 with captured_fd(2) as get_stderr: --> 349 self._build_extension( 350 extension, lib_dir, pgo_step_name='use' if args.pgo else None, quiet=args.quiet) 351 except (distutils.errors.CompileError, distutils.errors.LinkError): 352 # Build failed, print error message from compiler/linker
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Build/IpythonMagic.py:466, in CythonMagics._build_extension(self, extension, lib_dir, temp_dir, pgo_step_name, quiet) 465 old_threshold = distutils.log.set_threshold(distutils.log.DEBUG) --> 466 build_extension.run() 467 finally:
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/setuptools/_distutils/command/build_ext.py:345, in build_ext.run(self) 344 # Now actually compile and link everything. --> 345 self.build_extensions()
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/setuptools/_distutils/command/build_ext.py:467, in build_ext.build_extensions(self) 466 else: --> 467 self._build_extensions_serial()
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/setuptools/_distutils/command/build_ext.py:493, in build_ext._build_extensions_serial(self) 492 with self._filter_build_errors(ext): --> 493 self.build_extension(ext)
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/setuptools/_distutils/command/build_ext.py:548, in build_ext.build_extension(self, ext) 546 macros.append((undef,)) --> 548 objects = self.compiler.compile( 549 sources, 550 output_dir=self.build_temp, 551 macros=macros, 552 include_dirs=ext.include_dirs, 553 debug=self.debug, 554 extra_postargs=extra_args, 555 depends=ext.depends, 556 ) 558 # XXX outdated variable, kept here in case third-part code 559 # needs it.
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/setuptools/_distutils/ccompiler.py:600, in CCompiler.compile(self, sources, output_dir, macros, include_dirs, debug, extra_preargs, extra_postargs, depends) 599 continue --> 600 self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) 602 # Return all object filenames, not just the ones we just built.
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/setuptools/_distutils/unixccompiler.py:187, in UnixCCompiler._compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts) 186 except DistutilsExecError as msg: --> 187 raise CompileError(msg)
CompileError: command 'clang' failed with exit code 127
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last) File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Utils.py:513, in captured_fd(stream, encoding) 512 os.dup2(orig_stream, stream) # restore original stream --> 513 read_output() # keep the output in case it's used after closing the context manager 514 finally:
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Utils.py:501, in captured_fd..read_output(_output)
500 if not temp_file.closed:
--> 501 temp_file.seek(0)
502 _output[0] = temp_file.read()
OSError: [Errno 9] Bad file descriptor
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last) OSError: [Errno 9] Bad file descriptor
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last) File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Build/IpythonMagic.py:348, in CythonMagics.cython(self, line, cell) 347 with captured_fd(1) as get_stdout: --> 348 with captured_fd(2) as get_stderr: 349 self._build_extension( 350 extension, lib_dir, pgo_step_name='use' if args.pgo else None, quiet=args.quiet)
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Utils.py:61, in _TryFinallyGeneratorContextManager.exit(self, exc_type, exc_val, exc_tb) 60 try: ---> 61 next(self._gen) 62 except (StopIteration, GeneratorExit):
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Utils.py:498, in captured_fd(stream, encoding) 497 try: --> 498 with tempfile.TemporaryFile(mode="a+b") as temp_file: 499 def read_output(_output=[b'']):
OSError: [Errno 9] Bad file descriptor
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last) File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Utils.py:513, in captured_fd(stream, encoding) 512 os.dup2(orig_stream, stream) # restore original stream --> 513 read_output() # keep the output in case it's used after closing the context manager 514 finally:
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Utils.py:501, in captured_fd..read_output(_output)
500 if not temp_file.closed:
--> 501 temp_file.seek(0)
502 _output[0] = temp_file.read()
OSError: [Errno 9] Bad file descriptor
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last) OSError: [Errno 9] Bad file descriptor
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last) Cell In[11], line 1 ----> 1 get_ipython().run_cell_magic('cython', '-a', 'def geo_prog_cython(int n, int m):\n cdef int k\n cdef int summed\n for k in range(n):\n summed += m\n return summed\n')
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/IPython/core/interactiveshell.py:2478, in InteractiveShell.run_cell_magic(self, magic_name, line, cell) 2476 with self.builtin_trap: 2477 args = (magic_arg_s, cell) -> 2478 result = fn(*args, **kwargs) 2480 # The code below prevents the output from being displayed 2481 # when using magics with decodator @output_can_be_silenced 2482 # when the last Python token in the expression is a ';'. 2483 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Build/IpythonMagic.py:347, in CythonMagics.cython(self, line, cell) 345 get_stderr = get_stdout = None 346 try: --> 347 with captured_fd(1) as get_stdout: 348 with captured_fd(2) as get_stderr: 349 self._build_extension( 350 extension, lib_dir, pgo_step_name='use' if args.pgo else None, quiet=args.quiet)
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Utils.py:61, in _TryFinallyGeneratorContextManager.exit(self, exc_type, exc_val, exc_tb) 59 def exit(self, exc_type, exc_val, exc_tb): 60 try: ---> 61 next(self._gen) 62 except (StopIteration, GeneratorExit): 63 pass
File /private/var/containers/Bundle/Application/2D49FF0E-1952-42B1-B89A-09D41E04BB72/Carnets-sci.app/Library/lib/python3.11/site-packages/Cython/Utils.py:498, in captured_fd(stream, encoding) 496 orig_stream = os.dup(stream) # keep copy of original stream 497 try: --> 498 with tempfile.TemporaryFile(mode="a+b") as temp_file: 499 def read_output(_output=[b'']): 500 if not temp_file.closed:
OSError: [Errno 9] Bad file descriptor
What’s my mistake? A short google search showed that this error isn’t uncommon but I wasn’t too successful in finding a fix. Am I wrong in asserting we can use Cython within Carnets?
And another question: A few days ago my whole app layout changed. Now I have to manually choose „Open in NBClassic“ whenever I open an old or a new Notebook. Is there a setting to choose the NBClassic as default?
Thanks in advance! Cheers.