Written by

Senior Software Engineer
Question Ashok Kumar T · Aug 28, 2024

PIP install iris to use in python source file

Hello community,

How to install the iris  package installer for Python (pip) in python and import iris package in python source code. 

import iris
class Solution():
    iris.connection()

thanks!

$ZV: IRIS for Windows (x86-64) 2024.1 (Build 267.2U) Tue Apr 30 2024 16:41:33 EDT

Comments

Luis Angel Pérez Ramos · Aug 28, 2024

I install it directly from the intersystems_irispython-3.2.0-py3-none-any.whl file (here):

pip install intersystems_irispython-3.2.0-py3-none-any.whl

0
Ashok Kumar T  Aug 28, 2024 to Luis Angel Pérez Ramos

Thanks @Luis Angel Pérez Ramos 

It works. I downloaded and installed in python. However I got timeout error while trying to connect the IRIS in one machine  and it works in another machine. IDK pyodbc is required anyway it is also installed.

import iris

# Open a connection to the server
args = {'hostname':'127.0.0.1', 'port':52773,
    'namespace':'USER', 'username':'_SYSTEM', 'password':'SYS'
}

try:
    conn = iris.connect(**args)
    # Create an iris object
    irispy = iris.createIRIS(conn)
except Exception as e:
    # Handling the exception and printing the error
    print(f"An error occurred: {e}")

error mesage

    conn = iris.connect(**args)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\site-packages\iris\_IRISNative.py", line 167, in connect
    connection._connect(hostname, port, namespace, username, password, timeout, sharedmemory, logfile, sslcontext, autoCommit, isolationLevel, featureOptions)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\site-packages\iris\_IRISConnection.py", line 282, in _connect
    raise e
  File "C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\site-packages\iris\_IRISConnection.py", line 190, in _connect
    self._in_message._read_message_sql(sequence_number)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\site-packages\iris\_InStream.py", line 46, in _read_message_sql
    is_for_gateway = self.__read_message_internal(expected_message_id, expected_statement_id, type)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\site-packages\iris\_InStream.py", line 59, in __read_message_internal
    self.__read_buffer(header.buffer, 0, iris._MessageHeader._MessageHeader.HEADER_SIZE)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\site-packages\iris\_InStream.py", line 133, in __read_buffer
    data = self._device.recv(length)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\HP\AppData\Local\Programs\Python\Python312\Lib\site-packages\iris\_Device.py", line 40, in recv
    return self._socket.recv(len)
           ^^^^^^^^^^^^^^^^^^^^^^
TimeoutError: timed out

Thanks!

0
Raj Singh  Aug 28, 2024 to Ashok Kumar T

So now the problem isn't installing the Python library, but connecting to IRIS, correct? If you're using the above code on both servers, is the connection info the same on both servers?

0
Ashok Kumar T  Aug 28, 2024 to Raj Singh

Hello @Raj Singh 

Certainly. There is no issue in the python installation in my different machine (windows).  I'm using my IRIS local instance to connect in both. No major difference except the port number and I'm using the super server port number in both cases. 

0
Ashok Kumar T  Aug 29, 2024 to Raj Singh

And I'm trying to execute these lines from post  and git in to my .py source file. This functions are not available in iris library package.So, Is this code snippet is only applicable for embedded python. Please correct me If I'm doing wrong

If the below syntax works in python source file, What changed I need to do in my package.

# switch namespace to the %SYS namespace
    iris.system.Process.SetNamespace("%SYS")

    # set credentials to not expire
    iris.cls('Security.Users').UnExpireUserPasswords("*")

    print(iris.cls('dc.python.ObjectScript').Test())

Thanks!

0
Guillaume Rongier  Aug 29, 2024 to Ashok Kumar T

Here, those scripts are embedded python script, which are different from python script.

For whatever reason, embedded python iris module is called iris and official driver is also called iris from this wheel intersystems_irispython-3.2.0-py3-none-any.whl.

This create confusion and package collision, an community edition exist that solve this issue and allow you to use them both, you can install it from here : https://github.com/intersystems-community/intersystems-irispython

Another option is to use the iris wrapper : https://pypi.org/project/iris-embedded-python-wrapper/

Works well on macos, and i'm looking for feedback on windows machines.

0
Guillaume Rongier  Aug 29, 2024 to Ashok Kumar T

Hi,

My bet is that you are using web server port 52773 instead of 1972

Try this :

import iris

# Open a connection to the server
args = {'hostname':'127.0.0.1', 'port':1972,
    'namespace':'USER', 'username':'_SYSTEM', 'password':'SYS'
}

try:
    conn = iris.connect(**args)
    # Create an iris object
    irispy = iris.createIRIS(conn)
except Exception as e:
    # Handling the exception and printing the error
    print(f"An error occurred: {e}")
0
Evgeny Shvarov  Aug 29, 2024 to Ashok Kumar T

Is it embedded python or iris python native? (I always mess with them). If the first, try the following for the system:

; enabling callin for Embedded Pythondo##class(Security.Services).Get("%Service_CallIn",.prop)

set prop("Enabled")=1set prop("AutheEnabled")=48do##class(Security.Services).Modify("%Service_CallIn",.prop)
0