Installation

PyQ can be installed using the standard Python package management tool - pip. See Installing Python Modules for details. To install the latest version, run the following command

$ pip install pyq

Prerequisites

OS Support

PyQ has been tested and is supported on Linux and macOS 10.11 or later.

PyQ has support for Solaris, but has not been tested recently.

Windows is not supported yet.

Required Software

  • kdb+ 2.8 or later;
  • Python 2.7, or 3.5 or later;
  • GNU make, gcc or clang.

Installing from the package repository

Use following pip command to install the latest version of PyQ into your environment.

$ pip install pyq

To install another version, specify which version you would like to install:

$ pip install pyq==4.1.2

Installing from source code

  1. Get the source code using one of the following:

    • Clone the Github repository

      $ git clone https://github.com/enlnt/pyq.git
      
    • Download the source archive as a tar file or a zip file and extract it.

  2. Install the sources into your environment using pip:

    $ pip install <path to the source>
    

Installing PyQ into a virtual environment

PyQ was designed to work inside virtual environments. You can setup your system to use different versions of Python and/or kdb+ by using separate virtual environments.

In order to create a virtual environment, you need to install the virtualenv package:

$ [sudo] pip install virtualenv

Create a new virtualenv and activate it:

$ virtualenv path/to/virtualenv
$ source path/to/virtualenv/bin/activate

Download kdb+ and save into your ~/Downloads folder. Extract it into virtualenv:

$ unzip ${HOME}/Downloads/macosx.zip -d ${VIRTUAL_ENV}

If you have licensed version of the kdb+, you should create directory for it first:

$ mkdir -p ${VIRTUAL_ENV}/q && unzip path/to/m64.zip -d ${VIRTUAL_ENV}/q

Copy your kdb+ license file to ${VIRTUAL_ENV}/q or set the QLIC environment variable to the directory containing the license file and add it to the virtualenv’s activate file:

$ echo "export QLIC=path/to/qlic" >> ${VIRTUAL_ENV}/bin/activate
$ source ${VIRTUAL_ENV}/bin/activate

Install PyQ:

$ pip install pyq

Keeping PyQ up-to-date

You can upgrade PyQ to the latest version by running:

pip install -U pyq

Installing 32-bit PyQ with the free 32-bit kdb+ and Python 3.6 on 64-bit CentOS 7

Note

This guide was designed for installing Python 3.6. If you’re looking to use Python 2.7, you can follow this guide by replacing 3.6.0 with 2.7.13 where necessary.

1. Install development tools and libraries required to build 32-bit Python

$ sudo yum install gcc gcc-c++ rpm-build subversion git zip unzip bzip2 \
  libgcc.i686 glibc-devel.i686 glibc.i686 zlib-devel.i686 \
  readline-devel.i686 gdbm-devel.i686 openssl-devel.i686 ncurses-devel.i686 \
  tcl-devel.i686 libdb-devel.i686 bzip2-devel.i686 sqlite-devel.i686 \
  tk-devel.i686 libpcap-devel.i686 xz-devel.i686 libffi-devel.i686

2. Download, compile and install the 32-bit version of Python 3.6.0

We are going to install Python 3.6 into /opt/python3.6.i686:

$ mkdir -p ${HOME}/Archive ${HOME}/Build
$ sudo mkdir -p /opt/python3.6.i686
$ curl -Ls http://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz \
  -o ${HOME}/Archive/Python-3.6.0.tgz
$ tar xzvf ${HOME}/Archive/Python-3.6.0.tgz -C ${HOME}/Build
$ cd ${HOME}/Build/Python-3.6.0
$ export CFLAGS=-m32 LDFLAGS=-m32
$ ./configure --prefix=/opt/python3.6.i686 --enable-shared
$ LD_RUN_PATH=/opt/python3.6.i686/lib make
$ sudo make install
$ unset CFLAGS LDFLAGS

Let’s confirm we have a 32-bit Python on our 64-bit system:

$ uname -mip
x86_64 x86_64 x86_64
$ /opt/python3.6.i686/bin/python3.6 \
  -c "import platform; print(platform.processor(), platform.architecture())"
x86_64 ('32bit', 'ELF')

Yes, it is exactly what we desired.

3. Install virtualenv into Python installation

We are going to use virtual environments, download and extract virtualenv package:

$ curl -Ls https://pypi.org/packages/source/v/virtualenv/virtualenv-15.1.0.tar.gz \
  -o ${HOME}/Archive/virtualenv-15.1.0.tar.gz
$ tar xzf ${HOME}/Archive/virtualenv-15.1.0.tar.gz -C ${HOME}/Build

4. Create 32-bit Python virtual environment

Create a virtual environment:

$ /opt/python3.6.i686/bin/python3.6 ${HOME}/Build/virtualenv-15.1.0/virtualenv.py \
  ${HOME}/Work/pyq3

Enter the virtual environment that we created, confirm that we have a 32-bit Python there:

(pyq3) $ source ${HOME}/Work/pyq3/bin/activate
(pyq3) $ python -c "import struct; print(struct.calcsize('P') * 8)"
32

5. Download the 32-bit Linux x86 version of kdb+ from kx.com

Download kdb+ by following this link.

Save downloaded file as ${HOME}/Work/linux-x86.zip.

6. Extract kdb+ and install PyQ

Extract downloaded file:

(pyq3) $ unzip ${HOME}/Work/linux-x86.zip -d ${VIRTUAL_ENV}

Install PyQ (note, PyQ 3.8.2 or newer required):

(pyq3) $ pip install pyq>=3.8.2

6. Use PyQ

Start PyQ:

(pyq3) $ pyq
>>> import platform
>>> platform.processor()
'x86_64'
>>> platform.architecture()
('32bit', 'ELF')
>>> from pyq import q
>>> q.til(10)
k('0 1 2 3 4 5 6 7 8 9')

Installing PyQ on Ubuntu 16.04

Since Python provided by Ubuntu is statically linked, shared libraries need to be installed before PyQ can be installed.

Python 2

Install shared libraries:

$ sudo apt-get install libpython-dev libpython-stdlib python-pip python-virtualenv

Create and activate virtual environment:

$ python -m virtualenv -p $(which python2) py2
$ source py2/bin/activate

Install PyQ:

(py2) $ pip install pyq

Python 3

Install shared libraries:

$ sudo apt-get install libpython3-dev libpython3-stdlib python3-pip python3-virtualenv

Create and activate virtual environment:

$ python3 -m virtualenv -p $(which python3) py3
$ source py3/bin/activate

Install PyQ:

(py3) $ pip3 install pyq

Installing PyQ on macOS

In order to use PyQ with the free 32-bit kdb+ on macOS, you need a 32-bit version of Python. Out of the box, macOS Sierra and High Sierra come with a universal version of Python 2.7.10.

System Python 2

Install virtualenv module:

$ pip install virtualenv

If your system, does not have pip installed, follow pip installation guide.

Create and activate virtual environment:

$ virtualenv ${HOME}/pyq2
$ source ${HOME}/pyq2/bin/activate

Download kdb+ by following this link and save the downloaded file as ${HOME}/Downloads/macosx.zip.

Install kdb+ and PyQ:

(pyq2) $ unzip ${HOME}/Downloads/macosx.zip -d ${VIRTUAL_ENV}
(pyq2) $ pip install pyq

PyQ is ready and can be launched:

(pyq2) $ pyq

Brewing Universal Python

If you would like to use latest version of the Python 2.7 or Python 3, you will need to install it using package manager Homebrew.

  1. Install Homebrew. Installation instructions are available at Homebrew’s website.
  2. Install universal Python 2.7 and Python 3.6:
$ brew install --universal sashkab/python/python27 sashkab/python/python36
  1. Install virtualenv package.
$ /usr/local/opt/pythonXY/bin/pythonX -mpip install -U virtualenv

X is major version of the Python, Y - minor, i.e. 2.7 or 3.6.

  1. Create new virtual environment and activate it:
$ mkvirtualenv -p /usr/local/opt/pythonXY/bin/pythonX ${HOME}/pyq
$ source ${HOME}/pyq/bin/activate
  1. Download kdb+ by following this link and save the downloaded file as ${HOME}/Downloads/macosx.zip.
  2. Install kdb+ and PyQ:
(pyq) $ unzip ${HOME}/Downloads/macosx.zip -d ${VIRTUAL_ENV}
(pyq) $ pip install pyq

PyQ is ready and can be launched:

(pyq2) $ pyq

Experimental support for Windows

PyQ 4.1.0 introduced experimental support for Windows.

Requirements are:

Install PyQ:

pip install -U pyq

You can start PyQ by running

c:\q\w32\q.exe python.q

Note

You will have to press ^Z and then Enter key in order to get into Python REPL. This is known limitation of this version.

You can run tests too: first install required packages:

pip install pytest pytest-pyq

Then run:

set QBIN=c:\q\w32\q.exe
%QBIN% python.q -mpytest --pyargs pyq < nul

You can follow latest updates on Windows support on issue gh#1.

Installing Jupyter kernel

Since we have not ported the pyq executable to the Windows platform yet, setting up a working PyQ environment on Windows requires several manual steps.

First, it is strongly recommended to use a dedicated Python virtual environment and install q in %VIRTUAL_ENV%. Assuming that you have downloaded windows.zip from https://kx.com/download/ in your Downloads folder, enter the following commands:

python -mvenv py36
py36\Scripts\activate.bat
set QHOME=%VIRTUAL_ENV%\q
"C:\Program Files\7-Zip\7z.exe" x -y -o%VIRTUAL_ENV% %HOMEPATH%\Downloads\windows.zip
del %QHOME%\q.q
set PYTHONPATH=%VIRTUAL_ENV%\lib\site-packages
set QBIN=%QHOME%\w32\q.exe

Now you should be able to install jupyter, pyq and pyq-kernel in one command

pip install jupyter pyq pyq-kernel

Finally, to install pyq kernel specs, run

%QBIN% python.q -mpyq.kernel install

If everything is successful, you should see pyq_3 listed in the kernelspec list:

>jupyter kernelspec list
Available kernels:
  pyq_3      C:\Users\a\AppData\Roaming\jupyter\kernels\pyq_3
  python3    c:\users\a\py36\share\jupyter\kernels\python3

Now, start the notebook server

jupyter-notebook

and select “PyQ 3” from the “New” menu.

For examples of what can be done in a PyQ notebook, please see presentation.