Installation
PyQ can be installed using the standard Python package management tool pip
.
To install the latest version, run the following command
$ pip install pyq
Extras
For the best experience with PyQ, you should also install some third-party
packages such as numpy and IPython. The extra packages recommended by
the PyQ developers can be installed using the pip install pyq[all]
command.
Requirements
Operating system
Linux, macOS 10.11+
Solaris is supported, but has not been tested recently.
Windows is supported as an experiment
kdb+
V2.8+
Python
2.7, or 3.5+
Compiler
gcc
or clang
Installing from the package repository
Use the 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
-
Get the source code using one of the following:
-
Clone the Github repository
$ git clone https://github.com/kxsystems/pyq.git
-
Download the source archive as a tar file or a zip file and extract it.
-
-
Install the sources into your environment using
pip
:$ pip install path-to-the-source
Installing into a virtual environment
PyQ was designed to work inside virtual environments. You can set up your system to use different versions of Python and/or kdb+ by using separate virtual environments.
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 a license for kdb+, create a 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
Installing 32-bit PyQ with 32-bit kdb+ on a 64-bit CentOS 7
Python 2.7
This guide is for installing Python 3.6.
To use Python 2.7, replace 3.6.0
with 2.7.13
where necessary.
- Install the development tools and libraries 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
-
Download, compile and install 32-bit Python 3.6.0 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 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, exactly what we wanted.
-
We are going to use virtual environments, so download, extract, and install virtualenv
$ 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
-
Create a 32-bit Python virtual environment; first, create a virtual environment:
$ /opt/python3.6.i686/bin/python3.6 ${HOME}/Build/virtualenv-15.1.0/virtualenv.py \ ${HOME}/Work/pyq3
Enter the new virtual environment, confirm you have 32-bit Python there:
(pyq3) $ source ${HOME}/Work/pyq3/bin/activate (pyq3) $ python -c "import struct; print(struct.calcsize('P') * 8)" 32
-
Download the 32-bit Linux x86 version of kdb+ from kx.com and save it as
${HOME}/Work/linux-x86.zip
. -
Extract and install kdb+
(pyq3) $ unzip ${HOME}/Work/linux-x86.zip -d ${VIRTUAL_ENV}
-
Install PyQ 3.8.2 or newer
(pyq3) $ pip install pyq>=3.8.2
-
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 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 with 32-bit kdb+ on macOS
To use PyQ with the free 32-bit kdb+ on macOS, you need a 32-bit version of Python.
Python installed on macOS
MacOS Sierra and High Sierra ship with a universal version of Python 2.7.10.
System Python 2
Install the virtualenv module:
$ pip install virtualenv
If your system, does not have pip
installed, follow pip
installation guide.
Create and activate a virtual environment:
$ virtualenv ${HOME}/pyq2
$ source ${HOME}/pyq2/bin/activate
Download kdb+ 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
To use the latest version of Python 2.7 or Python 3, install it using the package manager Homebrew.
-
Install Homebrew.
-
Install universal Python 2.7 and Python 3.6:
$ brew install --universal sashkab/python/python27 sashkab/python/python36
-
Install the virtualenv package.
$ /usr/local/opt/pythonXY/bin/pythonX -mpip install -U virtualenv
X
is the major version of the Python;Y
the minor, i.e. 2.7 or 3.6. -
Create a new virtual environment and activate it:
$ /usr/local/opt/pythonXY/bin/pythonX -mvirtualenv -p /usr/local/opt/pythonXY/bin/pythonX ${HOME}/pyq $ source ${HOME}/pyq/bin/activate
-
Download kdb+ by following this link and save the downloaded file as
${HOME}/Downloads/macosx.zip
. -
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
Installing on Windows
PyQ 4.1.0 introduced experimental support for Windows.
Requirements are:
- Installation should be started using the Windows Command Prompt.
- Visual Studio 9 for Python, if using Python 2.7.x.
- Microsoft Build Tools for Visual Studio 2017, if using Python 3.6.x
- Ensure that kdb+ is installed under
C:\q
, or that theQHOME
environment variable is set to the location of the kdb+ executable.
Install PyQ:
pip install -U pyq
You can start PyQ by running
c:\q\w32\q.exe python.q
Known limitation
You will have to press ^Z
and then Enter
key in order to get into the Python REPL.
You can run tests too: first install the 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 the latest updates on Windows support on issue gh#1.
Installing the 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, you are strongly recommended to use a dedicated Python virtual environment and install q
in %VIRTUAL_ENV%
. Assuming that you have downloaded windows.zip
from kx.com into 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.
YouTube: What can be done in a PyQ notebook