KxSystems / pyq

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

Using PyQ in PyCharm #61

Closed jljs closed 6 years ago

jljs commented 6 years ago

Questions

Steps to reproduce the issue

Is there a way to run PyQ as an interpreter in PyCharm? I am trying to run PyQ as an interpreter in PyCharm, but I got the following error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/svc_tpmdb_dev/pycharm/pycharm-community-2018.1.2/helpers/pydev/pydevd.py", line 1664, in <module>
    main()
  File "/home/svc_tpmdb_dev/pycharm/pycharm-community-2018.1.2/helpers/pydev/pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/svc_tpmdb_dev/pycharm/pycharm-community-2018.1.2/helpers/pydev/pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/svc_tpmdb_dev/pycharm/pycharm-community-2018.1.2/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 11, in execfile
    stream = tokenize.open(file)  # @UndefinedVariable
  File "/home/svc_tpmdb_dev/.conda/envs/py36an440/lib/python3.6/tokenize.py", line 454, in open
    encoding, lines = detect_encoding(buffer.readline)
  File "/home/svc_tpmdb_dev/.conda/envs/py36an440/lib/python3.6/tokenize.py", line 431, in detect_encoding
    encoding = find_cookie(first)
  File "/home/svc_tpmdb_dev/.conda/envs/py36an440/lib/python3.6/tokenize.py", line 395, in find_cookie
    raise SyntaxError(msg)
SyntaxError: invalid or missing encoding declaration for '/home/svc_tpmdb_dev/.conda/envs/py36an440/bin/pyq'
We've got an error while stopping in post-mortem: <class 'KeyboardInterrupt'>

Expected result

Actual result

Workaround

If you know workaround, please provide it here.

sashkab commented 6 years ago

Yes, there is a workaround. You need to symlink python executable to pyq executable.

As we use virtual environments, we amended virtualenvironment creation process with following lines, depending on Python version:

For Python 2 we use:

(cd ${VIRTUAL_ENV}/bin && ln -sfn pyq python)

for Python 3 we use:

(cd ${VIRTUAL_ENV}/bin && ln -sfn pyq python3)
jljs commented 6 years ago

Thank you. I followed your instructions above. But I still get the following error when running it in PyCharm.

/home/svc_tpmdb_dev/.conda/envs/py36an440/bin/python3 /home/svc_tpmdb_dev/.conda/envs/py36an440/bin/pyq
  File "/home/svc_tpmdb_dev/.conda/envs/py36an440/bin/pyq", line 1
SyntaxError: Non-UTF-8 code starting with '\x96' in file /home/svc_tpmdb_dev/.conda/envs/py36an440/bin/pyq on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Process finished with exit code 1

Thanks

Jeffrey

jljs commented 6 years ago

Sorry. I have resolved the issue. Thank you very much. Your instructions above work.

Thanks

Jeffrey

abalkin commented 6 years ago

It looks like you have not configured PyCharm to run pyq as python executable. Go to Preferences and look for "Project Interpreter" . It should be set to the file (python or python3) that you symlinked to pyq.