To use Python with Vertica, you must either install the Vertica Open Source Python Client or install the pyodbc module and a Vertica ODBC driver on the machine where Python is installed. See Python prerequisites.
Python on Linux
Most Linux distributions come with Python preinstalled. If you want a more recent version, you can download and build it from the source code, though sometimes RPMs are also available. See the Python Web site and click an individual release for details. See also Python documentation.
To determine the Python version on your Linux operating systems, type the following at a command prompt:
# python -V
The system returns the version; for example:
Python 3.3.4
Python on Windows
Windows operating systems do not include Python by default. There are several different distributions of Python for windows:
-
The ActiveState Web site distributes a free Windows installer for Python called ActivePython.
-
The official Python.org site has installer packages for several versions of Python.
If you need installation instructions for Windows, see Using Python on Windows at python.org.
Python and unicode
When you are using Python, be sure that all of your components are using the same unicode text encoding. By default, the DSN Parameter ColumnsAsChar causes the ODBC driver to report CHAR and VARCHAR values as SQL_WCHAR. The driver returns these values to the driver manager in the encoding expected by the driver manager, as controlled by the DriverManagerEncoding parameter in vertica.ini. Similarly, your Python application must use the encoding expected by the driver manager. If any of these components use different encodings, your output can become garbled.
The Vertica Python client
The Vertica Python client is open source and available at https://github.com/vertica/vertica-python.
Using pyodbc and Vertica
Before you can connect to Vertica using pyodbc, you need to download the pyodbc module, which communicates with iODBC/unixODBC driver on UNIX operating systems and the ODBC Driver Manager for Windows operating systems.
The pyodbc module is an open source , MIT-licensed Python module, letting you use ODBC to connect to almost any database from Windows, Linux, Mac OS/X, and other operating systems.
Vertica supports multiple versions of pyodbc. See Python prerequisites for additional details.
Download the source distribution from the pyodbc Web site, unpack it and build it. Note that you need the unixODBC development package (in addition to the regular build tools) to build pyodbc. For example, on RedHat/CentOS run: yum install unixODBC-devel
, and on Ubuntu run: sudo apt-get install unixodbc-dev
. See the pyodbc wiki for detailed instructions.
Python clients and the UUID data type
Both the Vertica Python client and Vertica ODBC driver (that pyodbc interacts with) do not support Vertica's native UUID data type. Values retrieved using these drivers from a UUID column are converted to strings. When your client queries the metadata for a UUID column, the drivers report its data type as a string. Convert any UUID values that you want to insert into a UUID column to strings. Vertica automatically converts these values into the native UUID data type before inserting them into a table.