X

News, tips, partners, and perspectives for the Oracle Solaris operating system

Python on Solaris

James Mcpherson
Principal Software Engineer
Our colleagues in the Oracle Linux organisation have a nice writeup of their support for Python, and how to get cx_Oracle installed so you can access an Oracle Database.

I thought it would be useful to provide an equivalent guide for Oracle Solaris, so here it is.

Oracle Solaris has a long history of involvement with Python, starting at least 15 years ago (if not more!). Our Image Packaging System is about 94-95% Python, and we've got about 440k LoC (lines of code) written in Python directly in the ON consolidation. When you look at the Userland consolidation, however, that list grows considerably. From a practical point of view, you cannot install Oracle Solaris without using Python, and nor can you have a supportable installation unless you have this system-delivered Python and a whole lot of packages in /usr/lib/python2.7/vendor-packages. We are well aware of the immininent end of support for Python 2.7 so work is underway on migrating not just our modules and commands, but also our tooling -- so that we're not stuck when 2020 arrives.

So how does one find which libraries and modules we ship, without trawling through P5M files in the Userland gate? Simply search through the Oracle Solaris IPS publisher either using the web interface (ala https://pkg.oracle.com) or using the command line:

$ pkg search  -r \<python\>

which gives you a lot of package names. You'll notice that we version them via a suffix, so while you do get a few screenfuls of output, the list is about 423 packages long. Then to install it's very simple:

# pkg install <name-of-package>

just like you would for any other package.

I've made mention of this before, but I think it bears repeating: we make it very, very easy for you to install cx_Oracle and Instant Client so you can connect to the Oracle Database:

# pkg install -v cx_oracle
           Packages to install:        7
           Mediators to change:        1
     Estimated space available: 22.67 GB
Estimated space to be consumed:  1.01 GB
       Create boot environment:       No
Create backup boot environment:       No
          Rebuild boot archive:       No

Changed mediators:
  mediator instantclient:
           version: None -> 12.2 (vendor default)

Changed packages:
solaris
  consolidation/instantclient/instantclient-incorporation
    None -> 12.2.0.1.0-4
  database/oracle/instantclient-122
    None -> 12.2.0.1.0-4
  developer/oracle/odpi
    None -> 2.1.0-11.5.0.0.0.21.0
  library/python/cx_oracle
    None -> 6.1-11.5.0.0.0.21.0
  library/python/cx_oracle-27
    None -> 6.1-11.5.0.0.0.21.0
  library/python/cx_oracle-34
    None -> 6.1-11.5.0.0.0.21.0
  library/python/cx_oracle-35
    None -> 6.1-11.5.0.0.0.21.0

Then it's a simple matter of firing up your preferred Python version and uttering import cx_Oracle and away you go. Much like this:

>>> import cx_Oracle
>>> tns = """ORCLDNFS=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbkz)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcldnfs)))"""
>>> user = "admin"
>>> passwd = "welcome1"
>>> cnx = cx_Oracle.connect(user, passwd, tns)
>>> stmt = "select wait_class from v$system_event group by wait_class"
>>> curs = cnx.cursor()
>>> curs.execute(stmt).fetchall()
[('Concurrency',), ('User I/O',), ('System I/O',), ('Scheduler',), ('Configuration',), ('Other',), ('Application',), ('Queueing',), ('Idle',), ('Commit',), ('Network',)]

Simple!

 

 

Some notes on best practices for Python on Oracle Solaris

While we do aim to package and deliver useful packages, it does happen that perhaps there's a package you need which we don't ship, or which we ship an older version of. How do you get past that problem in a fashion which doesn't affect your system installation?

Unsurprisingly, the answer is not specific to Oracle Solaris: use Python Virtual Environments. While you could certainly use

$ pip install --user

you can still run afoul of incorrect versions of modules being loaded. Using a virtual environment is cheap, fits in very well with the concept of containerization, and makes the task of producing reproducible builds (aka deterministic compilation much simpler.

We use a similar concept when we're building ON, Solaris Userland and Solaris IPS.

For further information about Python packaging, please visit this tutorial, and review this article on Best Practices for Python dependency management which I've found to be one of the best written explanations about what to do, and why to do so.

If you have other questions about using Python in Oracle Solaris, please pop in to the Solaris Beta forum and let us know.

Join the discussion

Comments ( 5 )
  • David Lange Wednesday, March 27, 2019
    I've had a horrible time building python 3.6.8 with gcc due to libintl missing symbols, which I resolved by using sun 12 compiler to pick up the right order of libraries. Then the missing libffi dependency. I wish oracle would update to a recent release for solaris 10/11
  • Alan Coopersmith Saturday, April 6, 2019
    Solaris 10 is in extended support and only getting critical fixes now, not new features. If you want to run new software like Python 3.6, you need to upgrade to a new OS version, not stay on one originally released in 2005.

    Solaris 11.4 currently ships Python 2.7, 3.4, and 3.5, with 3.7 in the works for a future 11.4 SRU.
  • Darryl Thursday, April 25, 2019
    Solaris 10 comes with python 2.6 bundled. Is it even possible to upgrade to python 2.7 or later without moving to Solaris 11?
  • Alan Coopersmith Wednesday, May 15, 2019
    Python 2.7 is provided for Solaris 10 in patches 143506-13 (SPARC) & 143507-13 (x86).

    Oracle is only providing Python 3 for Solaris 11, so you'll either need to move to that for newer versions, or install them yourself from another source (or by building them from the open source code yourself).
  • David Lange Wednesday, July 10, 2019
    Alan, I understand that sol10 is fading, but even on sol11 there's issue with gcc and sunstudio12 with man libraries.

    1. Why don't they have an OS package for python not for development and the dev package we can add libraries too?

    2. Why can't some just test adding packages to python3.x for example the issues with pandas is really putting me to task:

    https://github.com/pandas-dev/pandas/issues/8780
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.