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 -i https://pyq.enlnt.com --no-binary pyq 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 -i https://pyq.enlnt.com --no-binary pyq pyq

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

$ pip install -i https://pyq.enlnt.com --no-binary pyq pyq==3.8

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 -i https://pyq.enlnt.com --no-binary pyq pyq

Keeping PyQ up-to-date

You can upgrade PyQ to the latest version by running:

pip install -i https://pyq.enlnt.com --no-binary pyq -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’ve got 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 we’ve just created, confirm we’ve got 32-bit Python in it:

(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 -i https://pyq.enlnt.com --no-binary pyq 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 -i https://pyq.enlnt.com --no-binary pyq 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 -i https://pyq.enlnt.com --no-binary pyq pyq