KxSystems / pyq

PyQ — Python for kdb+
http://code.kx.com/q/interfaces
Apache License 2.0
191 stars 49 forks source link

how to debug python in pyq with vscode #114

Closed fouvy closed 5 years ago

fouvy commented 5 years ago

Questions

Steps to reproduce the issue

I want to debug my python code in pyq which runs some query of table in kdb+. Anyone had solved this issue? This is my launch.json when i debug python code without q code under python 3.6 interpreter.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: train gbm",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

Anyone figured out how to setting pyq interpreter of launch.json in vscode?

Expected result

Actual result

Workaround

If you know workaround, please provide it here.

abalkin commented 5 years ago

This does not seem to be a pyq issue. Please try to direct your question to the k4 listbox or a vscode forum.

fouvy commented 5 years ago

Finally, I use pyvsd to debug my python code in pyq. First, install ptvsd

pip install ptvsd

Then, add debug code, in the python code we wanna debug:

# debug code section
import ptvsd
ptvsd.enable_attach(address=('localhost', 5678), redirect_output=True)
ptvsd.wait_for_attach()
breakpoint()

add python attach to launch.json

{"name":"Python: attach","type":"python","request":"attach","port":5678,"host":"localhost","pathMappings":[{"localRoot":"${workspaceFolder}/kdb","remoteRoot":"."}]}

At last, run code and use vscode attach

 pyq your_pyq_python_code.py
fouvy commented 5 years ago

Today, I found a new way to debug pyq without ptvsd in vscode. I have python2.7 python3.6 in my ubuntu, and installed pyq under python3.6 env without conda. First, update alternatives and bind pyq to python command

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/pyq 3

Second, config python command to pyq

sudo update-alternatives --config python

And select: 3 Finally, python command has alternative to pyq. And you can debug pyq code like common python code. Following is my bash command example run pyq:

fouvy@Zoom:~$ python
Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyq
>>> exit()

@sashkab @abalkin

sashkab commented 5 years ago

If you were to use PyQ inside virtual environment, as we recommend, you could have just symlink python to pyq and be done with it. But since you not following our suggestions -- feel free to re-invent the wheel ;-) I'm enjoying reading.