Coder Social home page Coder Social logo

jupyter-c-kernel's Introduction

Minimal C kernel for Jupyter

Use with Docker (recommended)

  • docker pull brendanrius/jupyter-c-kernel
  • docker run -p 8888:8888 brendanrius/jupyter-c-kernel
  • Copy the given URL containing the token, and browse to it. For instance:
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
   http://localhost:8888/?token=66750c80bd0788f6ba15760aadz53beb9a9fb4cf8ac15ce8

Manual installation

Works only on Linux and OS X. Windows is not supported yet. If you want to use this project on Windows, please use Docker.

  • Make sure you have the following requirements installed:
  • gcc
  • jupyter
  • python 3
  • pip

Step-by-step:

  • pip install jupyter-c-kernel
  • install_c_kernel
  • jupyter-notebook. Enjoy!

Example of notebook

Example of notebook

Custom compilation flags

You can use custom compilation flags like so:

Custom compulation flag

Here, the -lm flag is passed so you can use the math library.

Contributing

The docker image installs the kernel in editable mode, meaning that you can change the code in real-time in Docker. For that, just run the docker box like that:

git clone https://github.com/brendan-rius/jupyter-c-kernel.git
cd jupyter-c-kernel
docker run -v $(pwd):/jupyter/jupyter_c_kernel/ -p 8888:8888 brendanrius/jupyter-c-kernel

This clones the source, run the kernel, and binds the current folder (the one you just cloned) to the corresponding folder in Docker. Now, if you change the source, it will be reflected in http://localhost:8888 instantly. Do not forget to click "restart" the kernel on the page as it does not auto-restart.

License

MIT

jupyter-c-kernel's People

Contributors

brendan-rius avatar ddavidebor avatar ericjperry avatar jb08 avatar ntwuxc avatar qulogic avatar ryukinix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jupyter-c-kernel's Issues

kernel dies automatically when started

I installed the kernel using the script.
After that i restarted the server.
I have installed it on jupyterhub for students access.
Id dies and displays the following message:
The kernel has died, and the automatic restart has failed. It is possible the kernel cannot be restarted. If you are not able to restart the kernel, you will still be able to save the notebook, but running code will no longer work until the notebook is reopened.

no module named tempdir

-> % python3 /usr/local/bin/install_c_kernel
Traceback (most recent call last):
  File "/usr/local/bin/install_c_kernel", line 9, in <module>
    from IPython.utils.tempdir import TemporaryDirectory
ModuleNotFoundError: No module named 'IPython'

When i try to run install script i get following error message

files not executables

Hello,
I have problem witht the C kernel on linux.
Some files ".out" created are not executables, so I have this error on execution :

PermissionError: [Errno 13] Permission denied: '/tmp/tmp3ox946jx.out'

While making ls-la on temp I have this answer :
-rw------- 1 dpolizzi dpolizzi 0 nov. 15 09:27 tmp3ox946jx.out
-r-rwx--x--x 1 dpolizzi dpolizzi 8112 nov. 15 09:26 tmptv7rato1.out
w------- 1 dpolizzi dpolizzi 62 nov. 15 09:29 tmps_o257he.c
-rwx--x--x 1 dpolizzi dpolizzi 8112 nov. 15 09:29 tmpucnrmkhi.out
-rw------- 1 dpolizzi dpolizzi 62 nov. 15 09:26 tmpuhbujbdq.c

Have you a solution ?

Python 3 dependency

Unfortunately it's a bit of a problem for me to depend on Python 3. I tried modifying kernel.json to use Python 2, but it ran into a string processing error. Do you know if it would be difficult to make it work with Python 2? Thanks!

Make it possible to split implementation over multiple cells

Currently each cell should contain an entire functional c program. Notebooks would be much more descriptive if you could incrementally build up a program and intermix functions and markdown.

  • Markdown cell with some explanation
  • Code cell with a function
  • Markdown cell with some more explanation
  • Code cell with another function
  • Markdown cell with even more explanation
  • Code cell with main function calling other two functions

PyPi release outdated

the PyPi package is outdated (uploaded 2016-04-29) and thus missing the latest features (magics parsing πŸ˜„ ),

@brendan-rius could you please make a new release and upload it to pypi?

Kernel error

I performed the manual installation as given in the "README.md". But I am getting Kernel error during kernel start.
Failed to start the kernel
Unknown server error

Traceback (most recent call last):
  File "C:\Program Files\Anaconda3\lib\site-packages\notebook\base\handlers.py", line 457, in wrapper
    result = yield gen.maybe_future(method(self, *args, **kwargs))
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\gen.py", line 1015, in run
    value = future.result()
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\gen.py", line 1021, in run
    yielded = self.gen.throw(*exc_info)
  File "C:\Program Files\Anaconda3\lib\site-packages\notebook\services\sessions\handlers.py", line 62, in post
    kernel_id=kernel_id))
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\gen.py", line 1015, in run
    value = future.result()
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\gen.py", line 1021, in run
    yielded = self.gen.throw(*exc_info)
  File "C:\Program Files\Anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 79, in create_session
    kernel_name)
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\gen.py", line 1015, in run
    value = future.result()
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\gen.py", line 1021, in run
    yielded = self.gen.throw(*exc_info)
  File "C:\Program Files\Anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 92, in start_kernel_for_session
    self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\gen.py", line 1015, in run
    value = future.result()
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "C:\Program Files\Anaconda3\lib\site-packages\tornado\gen.py", line 285, in wrapper
    yielded = next(result)
  File "C:\Program Files\Anaconda3\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 87, in start_kernel
    super(MappingKernelManager, self).start_kernel(**kwargs)
  File "C:\Program Files\Anaconda3\lib\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
    km.start_kernel(**kwargs)
  File "C:\Program Files\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 243, in start_kernel
    **kw)
  File "C:\Program Files\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 189, in _launch_kernel
    return launch_kernel(kernel_cmd, **kw)
  File "C:\Program Files\Anaconda3\lib\site-packages\jupyter_client\launcher.py", line 123, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "C:\Program Files\Anaconda3\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files\Anaconda3\lib\subprocess.py", line 1224, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

OS - Win10
Python distro - Anaconda3 with Python 3.5.2

EDIT:
I also tried it in my Python 2.7.12 environment in Anaconda. The same problem there too.

Failed to start the kernel
Unknown server error

Traceback (most recent call last):
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\notebook\base\handlers.py", line 457, in wrapper
    result = yield gen.maybe_future(method(self, *args, **kwargs))
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\gen.py", line 1015, in run
    value = future.result()
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\gen.py", line 1021, in run
    yielded = self.gen.throw(*exc_info)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\notebook\services\sessions\handlers.py", line 62, in post
    kernel_id=kernel_id))
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\gen.py", line 1015, in run
    value = future.result()
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\gen.py", line 1021, in run
    yielded = self.gen.throw(*exc_info)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 79, in create_session
    kernel_name)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\gen.py", line 1015, in run
    value = future.result()
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\gen.py", line 1021, in run
    yielded = self.gen.throw(*exc_info)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 92, in start_kernel_for_session
    self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\gen.py", line 1015, in run
    value = future.result()
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\concurrent.py", line 237, in result
    raise_exc_info(self._exc_info)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\tornado\gen.py", line 285, in wrapper
    yielded = next(result)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 87, in start_kernel
    super(MappingKernelManager, self).start_kernel(**kwargs)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
    km.start_kernel(**kwargs)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\jupyter_client\manager.py", line 243, in start_kernel
    **kw)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\jupyter_client\manager.py", line 189, in _launch_kernel
    return launch_kernel(kernel_cmd, **kw)
  File "C:\Program Files\Anaconda3\envs\python27\lib\site-packages\jupyter_client\launcher.py", line 123, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "C:\Program Files\Anaconda3\envs\python27\lib\subprocess.py", line 711, in __init__
    errread, errwrite)
  File "C:\Program Files\Anaconda3\envs\python27\lib\subprocess.py", line 959, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified```

The c kernel does not appear in Jupyter

I am new in python..
I have followed the steps of manual installation.
pip install jupyter-c-kernel
when I open the jupyter
jupyter notebook
there is no c-kernel, there is only python. There is no error during installation. Is there any solution for this? Thank you.

Manual install fails

pip install jupyter-c-kernel

/bin/pip run on Thu Apr 28 20:27:48 2016
Downloading/unpacking jupyter-c-kernel
  Getting page https://pypi.python.org/simple/jupyter-c-kernel/
  Could not fetch URL https://pypi.python.org/simple/jupyter-c-kernel/: 404 Client Error: Not Found
  Will skip URL https://pypi.python.org/simple/jupyter-c-kernel/ when looking for download links for jupyter-c-kernel
  Getting page https://pypi.python.org/simple/
  URLs to search for versions for jupyter-c-kernel:
  * https://pypi.python.org/simple/jupyter-c-kernel/
  Getting page https://pypi.python.org/simple/jupyter-c-kernel/
  Could not fetch URL https://pypi.python.org/simple/jupyter-c-kernel/: 404 Client Error: Not Found
  Will skip URL https://pypi.python.org/simple/jupyter-c-kernel/ when looking for download links for jupyter-c-kernel
  Could not find any downloads that satisfy the requirement jupyter-c-kernel
Cleaning up...
No distributions at all found for jupyter-c-kernel

Extra information to install

Hi,

I have some problems to install c-kernel with step-by-step section information.

First, I have python 2 and 3 installed, but only 3 has ipykernel. Then, I needed to use pip3 to install. When I try to install with it I get an error:

$ install_c_kernel 
Installing IPython kernel spec
Traceback (most recent call last):
  File "/home/myuser/.local/bin/install_c_kernel", line 81, in <module>
    main(argv=sys.argv)
  File "/home/myuser/.local/bin/install_c_kernel", line 77, in main
    install_my_kernel_spec(user=user, prefix=prefix)
  File "/home/myuser/.local/bin/install_c_kernel", line 32, in install_my_kernel_spec
    KernelSpecManager().install_kernel_spec(td, 'bash', user=user, replace=True, prefix=prefix)
  File "/usr/lib/python3/dist-packages/jupyter_client/kernelspec.py", line 269, in install_kernel_spec
    shutil.copytree(source_dir, destination)
  File "/usr/lib/python3.5/shutil.py", line 315, in copytree
    os.makedirs(dst)
  File "/usr/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/usr/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/usr/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/share/jupyter'

I solved using --user flag in install_c_kernel:

$ install_c_kernel --user
Installing IPython kernel spec

$ jupyter-kernelspec list
Available kernels:
  bash       /home/myuser/.local/share/jupyter/kernels/bash
  ir         /home/myuser/.local/share/jupyter/kernels/ir
  python3    /usr/share/jupyter/kernels/python3

Except in this list c kernel is shown as bash, when I open jupyter it is shown as c.

Maybe is better add this extra information in step-by-step section. Maybe a note to use pip or pip3 and --user flag.

All the best,

Mario

Can we insert the codes from an external script?

Hello,

I wonder if there are some commands, like %load for Python, to load an external file to the notebook with C language. Or are there some clues for the users to use IPython kernel in a C language notebook?

Thanks!

C18?

Hi, Does this kernel support technical corrections and clarifications to defects in C18? Thanks, Paul

Running jupyter_c_kernel error on Termux for android

Hi, All:
I installed the jupyter on termux on Android. The C kernel already installed successed.
But running simple C "hello world" produced exception:
Could you give me a hand?

[IPKernelApp] ERROR | Exception in message handler: Traceback (most recent call last):
File "/data/data/com.termux/files/usr/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 232, in dispatch_shellhandler(stream, idents, msg)
File "/data/data/com.termux/files/usr/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 397, in execute_requestuser_expressions, allow_stdin)
File "/data/data/com.termux/files/usr/lib/python3.6/site-packages/jupyter_c_kernel/kernel.py", line 161, in do_execute
p = self.create_jupyter_subprocess([self.master_path, binary_file.name] + magics['args'])
File "/data/data/com.termux/files/usr/lib/python3.6/site-packages/jupyter_c_kernel/kernel.py", line 113, in create_jupyter_subprocess
lambda contents: self._write_to_stderr(contents.decode()))
File "/data/data/com.termux/files/usr/lib/python3.6/site-packages/jupyter_c_kernel/kernel.py", line 26, in __init__super().init(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0)
File "/data/data/com.termux/files/usr/lib/python3.6/subprocess.py", line 709, in __init__restore_signals, start_new_session)
File "/data/data/com.termux/files/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/data/data/com.termux/files/usr/tmp/tmp6qr8hzbm.out'

gcc compilation flags

Great project! I am trying to use fftw3, which requires gcc flag '-lfftw3'. Is it possible to configure compilation flags for each cell? It would be great if link path, include path, and flags can be configured dynamically.

Handle real-time communication with kernel

For now, the kernel waits for the program to end before sending stdout and stderr to the frontend.

Some programs are long to execute, in this case it is important that the kernel frequently updates the
frontend with the contents of stdout and stderr

Kernel error: Failed to start the kernel

Hi,

I got an unknown server error when my kernel in jupyter notebook failed to start. I'm relatively new to programming and I use Windows.

Here's what it shows in the error box:

Traceback (most recent call last):
File "C:\Users\Ray\Anaconda3\lib\site-packages\notebook\base\handlers.py", line 516, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\gen.py", line 1055, in run
value = future.result()
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "", line 4, in raise_exc_info
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\gen.py", line 1063, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\Ray\Anaconda3\lib\site-packages\notebook\services\sessions\handlers.py", line 75, in post
type=mtype))
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\gen.py", line 1055, in run
value = future.result()
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "", line 4, in raise_exc_info
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\gen.py", line 1063, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\Ray\Anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 79, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\gen.py", line 1055, in run
value = future.result()
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "", line 4, in raise_exc_info
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\gen.py", line 1063, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\Ray\Anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 92, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\gen.py", line 1055, in run
value = future.result()
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "", line 4, in raise_exc_info
File "C:\Users\Ray\Anaconda3\lib\site-packages\tornado\gen.py", line 307, in wrapper
yielded = next(result)
File "C:\Users\Ray\Anaconda3\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 94, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "C:\Users\Ray\Anaconda3\lib\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "C:\Users\Ray\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 257, in start_kernel
**kw)
File "C:\Users\Ray\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 203, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "C:\Users\Ray\Anaconda3\lib\site-packages\jupyter_client\launcher.py", line 128, in launch_kernel
proc = Popen(cmd, **kwargs)
File "C:\Users\Ray\Anaconda3\lib\subprocess.py", line 709, in init
restore_signals, start_new_session)
File "C:\Users\Ray\Anaconda3\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

Permission denied

hi,I found this project just now and I was surprised that C program can run on jupyternotebook.
But after I install jupyter-c-kernel by

sudo pip3 install jupyter-c-kernel
sudo install_c_kernel
jupyter notebook

I try to run a simple C program

#include <stdio.h>
int main(){
    printf("hello world");
    return 0;
}

there is no any output in jupyter notebook cell,and the jupyter shell output

Does not exist that file or directory
[IPKernelApp] WARNING | Unknown message type: 'comm_open'
[IPKernelApp] WARNING | Unknown message type: 'comm_open'
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
  File "/home/rousci/anaconda3/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 235, in dispatch_shell
    handler(stream, idents, msg)
  File "/home/rousci/anaconda3/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 399, in execute_request
    user_expressions, allow_stdin)
  File "/home/rousci/.local/lib/python3.6/site-packages/jupyter_c_kernel/kernel.te
    p = self.create_jupyter_subprocess([self.master_path, binary_file.name] + ma
  File "/home/rousci/.local/lib/python3.6/site-packages/jupyter_c_kernel/kernel.upyter_subprocess
    lambda contents: self._write_to_stderr(contents.decode()))
  File "/home/rousci/.local/lib/python3.6/site-packages/jupyter_c_kernel/kernel.
    super().__init__(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsiz
  File "/home/rousci/anaconda3/lib/python3.6/subprocess.py", line 707, in __init
    restore_signals, start_new_session)
  File "/home/rousci/anaconda3/lib/python3.6/subprocess.py", line 1326, in _exec
    raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

I've try to uninstall jupyter-c-kernel by sudo pip3 uninstall jupyter-c-kernel, but the C kernel still shows in the GUI interface

after I try to install jupyter-c-kernel again by

pip install jupyter-c-kernel --user
install-c-kernel --user
jupyter notebook

I got the same error.
I do not know how to solve it, maybe I know too title about Jupyter notebook or Ipython
anyway, thanks for your work.

Magics not working

When I type %cd .

I get

/var/folders/fj/f8yv9l9m8xjdwj001s7q3dd00000gw/T/tmpa3t59klq.c:1:1: error: expected identifier or '('
%cd .
^
1 error generated.
[C kernel] GCC exited with code 1, the executable will not be executed

Is anyone else seeing this?

Deprecation Warning when using latest Docker images

/opt/conda/bin/install_c_kernel:32: DeprecationWarning: replace is ignored. Installing a kernelspec always replaces an existing installation
KernelSpecManager().install_kernel_spec(td, 'c', user=user, replace=True, prefix=prefix)

issue when running

Hi Brendan,

I hit the following when I run jupyterhub and the C kernel you provide

No module named jupyter_c_kernel

and in the notebook it keeps trying to restart the kernel and getting the message again....
Any ideas about the problem?

Many thanks in advance.

IPKernelApp ERROR

OS - windos10
Python version - Python3.5.1

I start the C kernel, but when trying to compile the code like the following example:

#include <stdio.h>

int main() {
    printf("Hello world\n");
}

I got this error message under this cell:

realgcc.exe: error: unrecognized command line option '-rdynamic'
[C kernel] GCC exited with code 1, the executable will not be executed

and another shell that maintain the jupyter notebook show the following error message the same time:

realgcc.exe: error: unrecognized command line option '-rdynamic'
[IPKernelApp] ERROR | UNKNOWN MESSAGE TYPE: 'comm_open'

Kernel dies under JupyterHub

Kernel is identified by jupyterhub but fails to start

Dead kernel

The kernel has died, and the automatic restart has failed. It is possible the kernel cannot be restarted. If you are not able to restart the kernel, you will still be able to save the notebook, but running code will no longer work until the notebook is reopened
```.

undefined symbol: main

I have installed the kernel with --sys-prefix argument and now its listed on jupyter kernelspec list

Screen Shot

image

Traceback error while running install_c_kernel

I'm using Python 3.7.0 and while following the installation steps, I ran install_c_kernel and ran into a Traceback error`.

Traceback (most recent call last):
  File "/usr/bin/install_c_kernel", line 9, in <module>
    from IPython.utils.tempdir import TemporaryDirectory
  File "/usr/lib/python3.7/site-packages/IPython/__init__.py", line 55, in <module>
    from .terminal.embed import embed
  File "/usr/lib/python3.7/site-packages/IPython/terminal/embed.py", line 16, in <module>
    from IPython.terminal.interactiveshell import TerminalInteractiveShell
  File "/usr/lib/python3.7/site-packages/IPython/terminal/interactiveshell.py", line 22, in <module>
    from prompt_toolkit.shortcuts import create_prompt_application, create_eventloop, create_prompt_layout, create_output
ImportError: cannot import name 'create_prompt_application' from 'prompt_toolkit.shortcuts' (/usr/lib/python3.7/site-packages/prompt_toolkit/shortcuts/__init__.py)

I tried fixing the dependencies, yet no fixes.

The c kernel does not appear in JupyterHub

I installed JupyterHub this way:

$sudo su
#wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
#sh Anaconda3-5.0.1-Linux-x86_64.sh
#conda install -c conda-forge jupyterhub
#conda install notebook

And installed jupyter-c-kernel this way:

$sudo su
#pip install jupyter-c-kernel
#install_c_kernel

And I also installed other kernels:

#jupyter-kernelspec list
Available kernels:
  c                   /root/.local/share/jupyter/kernels/c
  java                /usr/local/anaconda3/share/jupyter/kernels/java
  matlab              /usr/local/anaconda3/share/jupyter/kernels/matlab
  python2             /usr/local/anaconda3/share/jupyter/kernels/python2
  python3             /usr/local/anaconda3/share/jupyter/kernels/python3
  xeus-cling-cpp11    /usr/local/anaconda3/share/jupyter/kernels/xeus-cling-cpp11
  xeus-cling-cpp14    /usr/local/anaconda3/share/jupyter/kernels/xeus-cling-cpp14
  xeus-cling-cpp17    /usr/local/anaconda3/share/jupyter/kernels/xeus-cling-cpp17
  ir                  /usr/local/share/jupyter/kernels/ir
  jupyter-php         /usr/local/share/jupyter/kernels/jupyter-php

Among these kernels, only c cannot appear in JupyterHub (but can appear in Jupyter), others can appear both in JupyterHub and Jupyter.

install_c_kernel: command not found

Hello, I am new to C and was trying to install this kernel in my Linux machine. Everything works fine except when I do: install_c_kernel, it says: install_c_kernel: command not found How do I fix this?

Wrong instruction about installing the kernel-specification

The manual installation has that flow:


    git clone [email protected]:brendan-rius/jupyter-c-kernel.git
    pip install jupyter-c-kernel
    cd jupyter-c-kernel
    jupyter-kernelspec install c_kernel

I'm ok until jupyter-kernelspec intall c_kernel. The problem is kernelspec are waiting for a kernel.json and you passing c_kernel whose has the .py files for internal function of kernel, not the specification. That doesn't works here. Beyond that, jupyter-kernelspec (at least the version I'm using now [4.1]) only works passing --user for user installing or global installing using sudo.

I think you need put your kernel.json in other local, maybe, in a isolated folder called C or c_spec. So that you can put in the instructions some like jupyter-kernelspec install c_spec --user and all will be fine.

I tested here and works fine.

By the way, great idea. Thanks for this. Is possible support input for stdin too like scanf calls? Would be really great.

PermissionError

Hi, I just installed the jupyter-c-kernel on my jupyterhub server (i installed it with sudo to have the kernel available for all the users).
When I try to execute the simple hello world example i got this log in the notebook shell output:

[I 2016-06-07 04:51:13.171 epinux kernelmanager:89] Kernel started: 22a3c6c7-8932-4cf2-b377-b4f33f571430
gcc: error: /usr/local/lib/python3.5/dist-packages/jupyter_c_kernel-1.0.0-py3.5.egg/jupyter_c_kernel/../resources/master.c: No such file or directory
[IPKernelApp] ERROR | UNKNOWN MESSAGE TYPE: 'comm_open'
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelbase.py", line 228, in dispatch_shell
    handler(stream, idents, msg)
  File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelbase.py", line 391, in execute_request
    user_expressions, allow_stdin)
  File "/usr/local/lib/python3.5/dist-packages/jupyter_c_kernel-1.0.0-py3.5.egg/jupyter_c_kernel/kernel.py", line 135, in do_execute
    p = self.create_jupyter_subprocess([self.master_path, binary_file.name])
  File "/usr/local/lib/python3.5/dist-packages/jupyter_c_kernel-1.0.0-py3.5.egg/jupyter_c_kernel/kernel.py", line 112, in create_jupyter_subprocess
    lambda contents: self._write_to_stderr(contents.decode()))
  File "/usr/local/lib/python3.5/dist-packages/jupyter_c_kernel-1.0.0-py3.5.egg/jupyter_c_kernel/kernel.py", line 25, in __init__
    super().__init__(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0)
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1544, in _execute_child
    raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied
[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelbase.py", line 228, in dispatch_shell
    handler(stream, idents, msg)
  File "/usr/local/lib/python3.5/dist-packages/ipykernel/kernelbase.py", line 391, in execute_request
    user_expressions, allow_stdin)
  File "/usr/local/lib/python3.5/dist-packages/jupyter_c_kernel-1.0.0-py3.5.egg/jupyter_c_kernel/kernel.py", line 135, in do_execute
    p = self.create_jupyter_subprocess([self.master_path, binary_file.name])
  File "/usr/local/lib/python3.5/dist-packages/jupyter_c_kernel-1.0.0-py3.5.egg/jupyter_c_kernel/kernel.py", line 112, in create_jupyter_subprocess
    lambda contents: self._write_to_stderr(contents.decode()))
  File "/usr/local/lib/python3.5/dist-packages/jupyter_c_kernel-1.0.0-py3.5.egg/jupyter_c_kernel/kernel.py", line 25, in __init__
    super().__init__(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0)
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1544, in _execute_child
    raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

I guess is an issue on how I installed the kernel, thanks for looking into this.

Support other C Language Version

In jupyter_c_kernel, codes would be compiled in C11, why not add support for other c version.

Currently, I've tried add an compile flag //%cflags:-std=gnu89, but it didn't work. After I checked the source code of the kernel.py, I found that the -std=c11 is hard coded in it. I tried removing it, and restart the kernel, but it doesn't work too.

So I wonder if it's hard to enable other c version, if not, would you please add an support for it?

Incorrect path to `master.c`

On row 86 in kernel.py there is a weird path for master.c - parent directory, subdirectory resources. Parent directory is (usually) system-wide dist_packages, which you should not touch. In any case, subdirectory resources does not exist.

I propose to change the line 86 to:
filepath = path.join(path.dirname(path.realpath(__file__)), 'master.c')
and copy the file master.c to the directory jupyter_c_kernel, where all other files reside.
Without that, I am gettings gcc errors in jupyter log and C kernel hangs forever.

math functions?

So if I need to use a math function I guess I want "-lm" or something. Is there some way to add linker options? Thanks!

default folder in the docker container?

Hi, I am able to run the docker container, but am unable to attach a local folder so I can save my work.

When I run the container, it says the user is "joyvan" so I am using the following command to attach a local folder to the container:

docker run -p 8888:8888 -it --user root -v /pathToMyFolder:/home/joyvan/work brendanrius/jupyter-c-kernel

This command format works for all my other containers to make pathToMyFolder available in the container, so I am wondering if the :/home/joyvan/ is wrong.

Docker container crashes immediately after run was called

I tried to run the docker container as described in the docs and it crashes immediately after the run command was executed (see full error log below).

My system is using old-fashioned docker-machine running on Mac OS 10.10.5 instead of the newer docker versions. docker version tells the following:

Client:
Version: 1.12.2
API version: 1.24
Go version: go1.6.3
Git commit: bb80604
Built: Tue Oct 11 17:00:50 2016
OS/Arch: darwin/amd64

Server:
Version: 1.12.2
API version: 1.24
Go version: go1.6.3
Git commit: bb80604
Built: Tue Oct 11 17:00:50 2016
OS/Arch: linux/amd64

The full error log as output by docker logs <container_name> shows an PermissionError as given per:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.5/site-packages/traitlets/traitlets.py", line 526, in get
    value = obj._trait_values[self.name]
KeyError: 'runtime_dir'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/conda/bin/jupyter-notebook", line 6, in <module>
    sys.exit(notebook.notebookapp.main())
  File "/opt/conda/lib/python3.5/site-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/opt/conda/lib/python3.5/site-packages/traitlets/config/application.py", line 652, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/opt/conda/lib/python3.5/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/opt/conda/lib/python3.5/site-packages/notebook/notebookapp.py", line 1140, in initialize
    self.init_configurables()
  File "/opt/conda/lib/python3.5/site-packages/notebook/notebookapp.py", line 901, in init_configurables
    connection_dir=self.runtime_dir,
  File "/opt/conda/lib/python3.5/site-packages/traitlets/traitlets.py", line 554, in __get__
    return self.get(obj, cls)
  File "/opt/conda/lib/python3.5/site-packages/traitlets/traitlets.py", line 533, in get
    value = self._validate(obj, dynamic_default())
  File "/opt/conda/lib/python3.5/site-packages/jupyter_core/application.py", line 99, in _runtime_dir_default
    ensure_dir_exists(rd, mode=0o700)
  File "/opt/conda/lib/python3.5/site-packages/ipython_genutils/path.py", line 167, in ensure_dir_exists
    os.makedirs(path, mode=mode)
  File "/opt/conda/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/opt/conda/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/opt/conda/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/home/jovyan/.local/share'
Traceback (most recent call last):
  File "/opt/conda/lib/python3.5/site-packages/traitlets/traitlets.py", line 526, in get
    value = obj._trait_values[self.name]
KeyError: 'runtime_dir'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/conda/bin/jupyter-notebook", line 6, in <module>
    sys.exit(notebook.notebookapp.main())
  File "/opt/conda/lib/python3.5/site-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/opt/conda/lib/python3.5/site-packages/traitlets/config/application.py", line 652, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/opt/conda/lib/python3.5/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/opt/conda/lib/python3.5/site-packages/notebook/notebookapp.py", line 1140, in initialize
    self.init_configurables()
  File "/opt/conda/lib/python3.5/site-packages/notebook/notebookapp.py", line 901, in init_configurables
    connection_dir=self.runtime_dir,
  File "/opt/conda/lib/python3.5/site-packages/traitlets/traitlets.py", line 554, in __get__
    return self.get(obj, cls)
  File "/opt/conda/lib/python3.5/site-packages/traitlets/traitlets.py", line 533, in get
    value = self._validate(obj, dynamic_default())
  File "/opt/conda/lib/python3.5/site-packages/jupyter_core/application.py", line 99, in _runtime_dir_default
    ensure_dir_exists(rd, mode=0o700)
  File "/opt/conda/lib/python3.5/site-packages/ipython_genutils/path.py", line 167, in ensure_dir_exists
    os.makedirs(path, mode=mode)
  File "/opt/conda/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/opt/conda/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/opt/conda/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/home/jovyan/.local/share'
Traceback (most recent call last):
  File "/opt/conda/lib/python3.5/site-packages/traitlets/traitlets.py", line 526, in get
    value = obj._trait_values[self.name]
KeyError: 'runtime_dir'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/conda/bin/jupyter-notebook", line 6, in <module>
    sys.exit(notebook.notebookapp.main())
  File "/opt/conda/lib/python3.5/site-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/opt/conda/lib/python3.5/site-packages/traitlets/config/application.py", line 652, in launch_instance
    app.initialize(argv)
  File "<decorator-gen-7>", line 2, in initialize
  File "/opt/conda/lib/python3.5/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/opt/conda/lib/python3.5/site-packages/notebook/notebookapp.py", line 1140, in initialize
    self.init_configurables()
  File "/opt/conda/lib/python3.5/site-packages/notebook/notebookapp.py", line 901, in init_configurables
    connection_dir=self.runtime_dir,
  File "/opt/conda/lib/python3.5/site-packages/traitlets/traitlets.py", line 554, in __get__
    return self.get(obj, cls)
  File "/opt/conda/lib/python3.5/site-packages/traitlets/traitlets.py", line 533, in get
    value = self._validate(obj, dynamic_default())
  File "/opt/conda/lib/python3.5/site-packages/jupyter_core/application.py", line 99, in _runtime_dir_default
    ensure_dir_exists(rd, mode=0o700)
  File "/opt/conda/lib/python3.5/site-packages/ipython_genutils/path.py", line 167, in ensure_dir_exists
    os.makedirs(path, mode=mode)
  File "/opt/conda/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/opt/conda/lib/python3.5/os.py", line 231, in makedirs
    makedirs(head, mode, exist_ok)
  File "/opt/conda/lib/python3.5/os.py", line 241, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/home/jovyan/.local/share'

Installation Steps Ubuntu 16

Hello,
Thank you for the great work on this project!
I am new to C, and the time saved in using the notebooks vs compile then run, is very noticeable.
It also makes for a much nicer work flow.

These are the steps I used to install the jupyter-c-kernel.
The only difference is using pip3 and install ipykernel.
sudo pip3 install jupyter-c-kernel
git clone https://github.com/brendan-rius/jupyter-c-kernel.git
cd jupyter-c-kernel/
jupyter-kernelspec install c_spec/
sudo pip3 install ipykernel
jupyter-notebook

New Tag?

Would it be possible to create a new tag for the current state of the repository? The install script is very helpful and it would be nice to have access to that via a tag rather than having to install from master.

Thanks!

ANSI C and flags

First of all, great project!

When using the cflag -ansi, commenting by using // can't be used so the code won't compile and standard error is produce.

The code for test:

//%cflags:-ansi -Wall -pedantic

#include <stdio.h>

int main()
{
   printf("Hello, World!");
   return 0;
}

The Error:

/tmp/tmpuzigbjpm.c:1:1: error: C++ style comments are not allowed in ISO C90
 //%cflags:-ansi -Wall -pedantic
 ^
/tmp/tmpuzigbjpm.c:1:1: error: (this will be reported only once per input file)
[C kernel] GCC exited with code 1, the executable will not be executed

Screenshot for additional information:

screen shot 2018-12-18 at 17 42 41

Thanks!

command line arguments?

Is it possible to provide command line arguments to main? Sorry if it should be obvious and I just haven't spotted it yet.

thanks,
-steve

Traffic Sign Recognition: valueError: Only call `sparse_softmax_cross_entropy_with_logits` with named arguments (labels=..., logits=..., ...)

I was running the example tutorial from https://github.com/waleedka/traffic-signs-tensorflow/blob/master/notebook1.ipynb and when I reached the Minimum Viable Model portion, that's when I ran into the error valueError: Only call sparse_softmax_cross_entropy_with_logits with named arguments (labels=..., logits=..., ...). However, the tutorial itself seems to work, but when I ran it myself that's how I got the error. Here's the actual code:
`
graph = tf.Graph()

with graph.as_default():
# Placeholders for inputs and labels.
images_ph = tf.placeholder(tf.float32, [None, 32, 32, 3])
labels_ph = tf.placeholder(tf.int32, [None])

# Flatten input from: [None, height, width, channels]
# To: [None, height * width * channels] == [None, 3072]
images_flat = tf.contrib.layers.flatten(images_ph)

# Fully connected layer. 
# Generates logits of size [None, 62]
logits = tf.contrib.layers.fully_connected(images_flat, 62, tf.nn.relu)

# Convert logits to label indexes (int).
# Shape [None], which is a 1D vector of length == batch_size.
predicted_labels = tf.argmax(logits, 1)

# Define the loss function. 
# Cross-entropy is a good choice for classification.
loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels_ph))

# Create training op.
train = tf.train.AdamOptimizer(learning_rate=0.001).minimize(loss)

# And, finally, an initialization op to execute before training.
# TODO: rename to tf.global_variables_initializer() on TF 0.12.
init = tf.initialize_all_variables()

print("images_flat: ", images_flat)
print("logits: ", logits)
print("loss: ", loss)
print("predicted_labels: ", predicted_labels)`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.