KxSystems / jupyterq

Jupyter kernel for kdb+
https://code.kx.com/q/interfaces
Apache License 2.0
105 stars 46 forks source link

Instructions to set up kdb kernel properly #49

Closed RemKamal closed 4 years ago

RemKamal commented 4 years ago

Hello all, are there instructions on how to set up kdb kerner for jupyter? I followed this page, created a json file, and copy-pasted there the info from: https://code.kx.com/v2/ml/jupyterq/notebooks/

but I get this error when I open Q notebook in Jupyter: Traceback (most recent call last): File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/web.py", line 1512, in _execute result = yield result File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/gen.py", line 1055, in run value = future.result() File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/concurrent.py", line 238, in result raise_exc_info(self._exc_info) File "", line 4, in raise_exc_info File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/gen.py", line 1063, in run yielded = self.gen.throw(exc_info) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/notebook/services/sessions/handlers.py", line 73, in post type=mtype)) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/gen.py", line 1055, in run value = future.result() File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/concurrent.py", line 238, in result raise_exc_info(self._exc_info) File "", line 4, in raise_exc_info File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/gen.py", line 1063, in run yielded = self.gen.throw(exc_info) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/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 "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/gen.py", line 1055, in run value = future.result() File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/concurrent.py", line 238, in result raise_exc_info(self._exc_info) File "", line 4, in raise_exc_info File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/gen.py", line 1063, in run yielded = self.gen.throw(*exc_info) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/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 "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/gen.py", line 1055, in run value = future.result() File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/concurrent.py", line 238, in result raise_exc_info(self._exc_info) File "", line 4, in raise_exc_info File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/tornado/gen.py", line 307, in wrapper yielded = next(result) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/notebook/services/kernels/kernelmanager.py", line 148, in start_kernel super(MappingKernelManager, self).start_kernel(kwargs) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel km.start_kernel(kwargs) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/manager.py", line 257, in start_kernel kw) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/manager.py", line 203, in _launch_kernel return launch_kernel(kernel_cmd, kw) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/launcher.py", line 128, in launch_kernel proc = Popen(cmd, **kwargs) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/subprocess.py", line 709, in init restore_signals, start_new_session) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/subprocess.py", line 1344, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'q': 'q'

============================================

I checked q and QHOME: -bash-4.2$ which q alias q='/home/nynfs01/svaury/q//l64/q' /home/nynfs01/svaury/q/l64/q -bash-4.2$ echo $QHOME /home/nynfs01/svaury/q/ -bash-4.2$

I do not use conda on the server. -bash-4.2$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.5 (Maipo)

KDB+ 3.5 2017.11.30 Copyright (C) 1993-2017 Kx Systems l64/ 88(1)core 773717MB

Thanks, Rem

cmccarthy1 commented 4 years ago

Hi Rem,

Instructions for non conda install are within the README here. This should pick up your QHOME and install accordingly. It will require that you manually/pip install the python requirements but should allow you to install the kernel.

In this case you will also need to have embedPy installed which is a requirement of JupyterQ (this would have been handled via the conda install).

Please follow up with any questions and revert here if fixed so we can cloase the issue·

Hope this helps, Conor

RemKamal commented 4 years ago

Hello Conor, thank you for the reply!

I was under impression when I install pyq, embedpy gets added too [1]. Just to confirm, do you suggest to install it? In may case, I would follow the first option on the installation page: Download and install a release. Please let me know.

Thanks, Rem

[1] https://github.com/KxSystems/pyq/issues/30#issuecomment-391815858

cmccarthy1 commented 4 years ago

Yes in the current version of PyQ I believe that is the case. If your system has embedPy installed then you should not need to go through that step.

The install of JupyterQ using the link pointing to the README in my initial message should be sufficient provided you have all requirements installed.

RemKamal commented 4 years ago

Hello Conor, according to instructions everything is installed, no errors. Also, I have an alias for q, QHOME variable, and QHOME in the PATH set up. However, running this command, I get:

-bash-4.2$ jupyter console --kernel=qpk --debug [ZMQTerminalIPythonApp] Searching ['/home/nynfs01/rkamal2', '/home/nynfs01/rkamal2/.jupyter', '/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/etc/jupyter', '/usr/local/etc/jupyter', '/etc/jupyter'] for config files [ZMQTerminalIPythonApp] Looking for jupyter_config in /etc/jupyter [ZMQTerminalIPythonApp] Looking for jupyter_config in /usr/local/etc/jupyter [ZMQTerminalIPythonApp] Looking for jupyter_config in /home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/etc/jupyter [ZMQTerminalIPythonApp] Looking for jupyter_config in /home/nynfs01/rkamal2/.jupyter [ZMQTerminalIPythonApp] Looking for jupyter_config in /home/nynfs01/rkamal2 [ZMQTerminalIPythonApp] Looking for jupyter_console_config in /etc/jupyter [ZMQTerminalIPythonApp] Looking for jupyter_console_config in /usr/local/etc/jupyter [ZMQTerminalIPythonApp] Looking for jupyter_console_config in /home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/etc/jupyter [ZMQTerminalIPythonApp] Looking for jupyter_console_config in /home/nynfs01/rkamal2/.jupyter [ZMQTerminalIPythonApp] Looking for jupyter_console_config in /home/nynfs01/rkamal2 [ZMQTerminalIPythonApp] Connection File not found: /run/user/6411/jupyter/kernel-24735.json Traceback (most recent call last): File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/bin/jupyter-console", line 11, in sys.exit(main()) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_core/application.py", line 266, in launch_instance return super(JupyterApp, cls).launch_instance(argv=argv, *kwargs) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance app.initialize(argv) File "</home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/decorator.py:decorator-gen-116>", line 2, in initialize File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error return method(app, args, kwargs) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_console/app.py", line 141, in initialize self.init_shell() File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_console/app.py", line 109, in init_shell JupyterConsoleApp.initialize(self) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/consoleapp.py", line 334, in initialize self.init_kernel_manager() File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/consoleapp.py", line 288, in init_kernel_manager self.kernel_manager.start_kernel(kwargs) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/manager.py", line 244, in start_kernel kernel_cmd = self.format_kernel_cmd(extra_arguments=extra_arguments) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/manager.py", line 169, in format_kernel_cmd cmd = self.kernel_spec.argv + extra_arguments File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/manager.py", line 81, in kernel_spec self._kernel_spec = self.kernel_spec_manager.get_kernel_spec(self.kernel_name) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/kernelspec.py", line 236, in get_kernel_spec raise NoSuchKernel(kernel_name) jupyter_client.kernelspec.NoSuchKernel: No such kernel named qpk

Could you tell me please, what I am missing?

-bash-4.2$ jupyter kernelspec list Available kernels: kdb_kernel /home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/share/jupyter/kernels/kdb_kernel python3 /home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/share/jupyter/kernels/python3

I also copied json file to /home/nynfs01/rkamal2, but does not help.

Thanks, Rem

cmccarthy1 commented 4 years ago

It looks like you don’t have the kernel installed in the correct location according to your kernelspec list or it’s named incorrectly. Is the kdb_kernel a name that you have assigned to the kernel yourself? If so renaming to qpk would be required in order to ensure that the behaviour of the kernel is consistent with what we would expect from the kernel and would explain why running jupyter console --kernel=qpk --debug would not pick up the kernel.

Can you also please check that embedPy is correctly installed, there can be conflicts between pyq and embedPy resulting from both using a defined p.k file in $QHOME. If embedPy is installed you should be able to evaluate the following

$q p.k
q).p.eval["list.pop"][;0]
// returning
{[f;x]embedPy[f;x]}[foreign]enlist[;0]

If this is not the case it may be advisable to install pyq and embedPy in separate environments, issues with conflicts of this type and ease of install are largely why the conda installs are preferable although I appreciate this is not always feasible.

It should also be noted that the JupyterQ kernel will not work with PyQ, just to preempt this as a potential issue given your use of PyQ. In order to install the PyQ kernel you would need to follow the instructions at https://code.kx.com/v2/interfaces/pyq/install/#installing-the-jupyter-kernel

RemKamal commented 4 years ago

Hello Conor, thanks for the message and happy holidays!

I have been waiting for the admin to let me change the qpk. Meanwhile, I tried to install embedPy on my mac laptop using conda. I do have a working 32-bit kdb and Jupyter. I tried to install embedpy on top. In fact, whether I try to install embedpy (or kdb using conda just for testing purpose), I get the same errors. Does it look at the wrong repo?

Rem$ conda install -c kx kdb Collecting package metadata (current_repodata.json): done Solving environment: - The environment is inconsistent, please check the package plan carefully The following packages are causing the inconsistency:

cmccarthy1 commented 4 years ago

Hi Remi,

Happy Holidays.

No that repository is correct. What you're seeing there has been an issue with conda for the last number of months since an update to conda 4.6.9 as noted here, following some of the methods outlined in that issue to resolve your problem may help or downgrading to an older version of conda may prove useful. Looking at the output this is not the same issue as the issue you're seeing on the server.

If you are conda installing kdb and embedPy for testing purposes and currently have a 32 bit version of kdb on your computer however I would strongly suggest installing within an environment as outlined in one of the previous messages this will reduce significantly the time it takes to get the system up and running.

The suggestion to install in a clean environment https://github.com/KxSystems/jupyterq#install-with-conda is largely to reduce conflicts which arise with packages on your system currently including but not limited to PyQ and should reduce errors like you're seeing above.

Hope this helps.

Conor

RemKamal commented 4 years ago

Hello Conor, thanks for the reply! Will check the conda issue once I get to my laptop, appreciate your help!

Regarding the server installation, after renaming the kernel to qpk, here is what it gives:

'2020.01.02T11:03:43.140 .p.eval [4] /home/nynfs01/svaury/q.64bit/jupyterq_pyzmq.q:2: pypop:.p.eval["list.pop"][;0] ^ Traceback (most recent call last): File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_console/ptshell.py", line 323, in init_kernel_info reply = self.client.get_shell_msg(timeout=1) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/client.py", line 77, in get_shell_msg return self.shell_channel.get_msg(*args, **kwargs) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_client/blocking/channels.py", line 57, in get_msg raise Empty queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/bin/jupyter-console", line 11, in sys.exit(main()) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_core/application.py", line 266, in launch_instance return super(JupyterApp, cls).launch_instance(argv=argv, kwargs) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance app.initialize(argv) File "</home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/decorator.py:decorator-gen-116>", line 2, in initialize File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error return method(app, *args, *kwargs) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_console/app.py", line 141, in initialize self.init_shell() File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_console/app.py", line 114, in init_shell client=self.kernel_client, File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/traitlets/config/configurable.py", line 412, in instance inst = cls(args, kwargs) File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_console/ptshell.py", line 272, in init self.init_kernel_info() File "/home/nynfs01/svaury/bin/_dc2nix2d193/Python-3.6.3/lib/python3.6/site-packages/jupyter_console/ptshell.py", line 326, in init_kernel_info raise RuntimeError("Kernel didn't respond to kernel_info_request") RuntimeError: Kernel didn't respond to kernel_info_request

cmccarthy1 commented 4 years ago

That looks like it may be an issue with a conflict with PyQ. As mentioned previously you'll need to have the version of p.k which is associated with embedPy in order to ensure that your system will behave as expected.

To that end I would recommend ensuring that you follow the steps outlined here making sure to follow each step in the process which includes a fresh install of embedPy and ensuring that q is on the PATH and not just an alias which seems to be the case based on your initial message.

Again I would recommend that this be done in an environment if possible to ensure you limit conflicts with your current system but following the steps from above closely should ensure that you are able to get the system up and running.

RemKamal commented 4 years ago

Hello Conor,

thanks for the reply. I followed largely the same steps again for the server, did not have errors in between, but still the Q kernel complains about the "q" not found, not sure which of packages causes it and why :( Is there a plan for the future to move the installation to "1 package does it all" or anything like that?

Thanks, Rem

cmccarthy1 commented 4 years ago

Can you please elaborate on where and why you have deviated from the install instructions if possible?

I suspect that your q is not on the PATH but is still an alias? f this is the case that will not be sufficient and may indicate why you're not finding "q".

There are currently no plans to modify the instructions or add a "1 package does all" type installation (this is handled with the conda installs)

RemKamal commented 4 years ago

Hello Conor, some steps are made by admin, some by me, I don't have full control over the server.

I will check the conda setup on the laptop, meanwhile, and let you know.

Thanks, Rem

cmccarthy1 commented 4 years ago

Hi Rem,

I'm closing this issue for now. If you are still having issues and can provide more information relating to how you have deviated from the recommended install instructions feel free to reopen and elaborate.

All the best, Conor