"ImportError: cannot import name 'base_impl'" while running standalone python zipapp executable

90 views Asked by At

I am running oracle linux 7.9 with python 3.6.8. I created a standalone python zipapp executable following this tutorial. When I run the resulting executable I get the following error(1m is just an argument that script expects)

oracle@hostname:~/scripts/inspirit/ora_runner2> python3 standalone_ora_runner_native.pyz 1m
Traceback (most recent call last):
  File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "standalone_ora_runner_native.pyz/__main__.py", line 71, in <module>
  File "standalone_ora_runner_native.pyz/oracledb/__init__.py", line 56, in <module>
  File "standalone_ora_runner_native.pyz/oracledb/connection.py", line 45, in <module>
ImportError: cannot import name 'base_impl'

base_impl is a module that oracledb library tries to import but fails. Contents of oracledb folder are like following

oracle@hostname:~/scripts/inspire/ora_runner2/standalone_testing/oracledb> ll
total 28588
-rw-r--r-- 1 oracle oinstall    19013 Nov  9 13:32 aq.py
-rwxr-xr-x 1 oracle oinstall  8927248 Nov  9 13:32 base_impl.cpython-36m-x86_64-linux-gnu.so
-rw-r--r-- 1 oracle oinstall    49764 Nov  9 13:32 connection.py
-rw-r--r-- 1 oracle oinstall    32021 Nov  9 13:32 connect_params.py
-rw-r--r-- 1 oracle oinstall     4001 Nov  9 13:32 constants.py
-rw-r--r-- 1 oracle oinstall     2909 Nov  9 13:32 constructors.py
-rw-r--r-- 1 oracle oinstall    35714 Nov  9 13:32 cursor.py
-rw-r--r-- 1 oracle oinstall    11852 Nov  9 13:32 dbobject.py
-rw-r--r-- 1 oracle oinstall     1827 Nov  9 13:32 defaults.py
-rw-r--r-- 1 oracle oinstall     5403 Nov  9 13:32 driver_mode.py
-rw-r--r-- 1 oracle oinstall     3130 Nov  9 13:32 dsn.py
-rw-r--r-- 1 oracle oinstall    22861 Nov  9 13:32 errors.py
-rw-r--r-- 1 oracle oinstall     1811 Nov  9 13:32 exceptions.py
-rw-r--r-- 1 oracle oinstall     5679 Nov  9 13:32 fetch_info.py
-rw-r--r-- 1 oracle oinstall     1995 Nov  9 13:32 future.py
-rw-r--r-- 1 oracle oinstall     6172 Nov  9 13:32 __init__.py
-rw-r--r-- 1 oracle oinstall     6078 Nov  9 13:32 lob.py
-rw-r--r-- 1 oracle oinstall    31742 Nov  9 13:32 pool_params.py
-rw-r--r-- 1 oracle oinstall    35264 Nov  9 13:32 pool.py
drwxr-xr-x 2 oracle oinstall     4096 Nov  9 13:32 __pycache__
-rw-r--r-- 1 oracle oinstall        0 Nov  9 13:32 py.typed
-rw-r--r-- 1 oracle oinstall    28158 Nov  9 13:32 soda.py
-rw-r--r-- 1 oracle oinstall    11078 Nov  9 13:32 subscr.py
-rwxr-xr-x 1 oracle oinstall  5944536 Nov  9 13:32 thick_impl.cpython-36m-x86_64-linux-gnu.so
-rwxr-xr-x 1 oracle oinstall 14027328 Nov  9 13:32 thin_impl.cpython-36m-x86_64-linux-gnu.so
-rw-r--r-- 1 oracle oinstall     3382 Nov  9 13:32 utils.py
-rw-r--r-- 1 oracle oinstall     6629 Nov  9 13:32 var.py
-rw-r--r-- 1 oracle oinstall     1533 Nov  9 13:32 version.py

How I prepared the zipapp

  • python -m pip install -r requirements.txt --target ora_runner/
  • python -m zipapp ora_runner/ -o standalone_ora_runner_native.pyz -p "python"

Problem in this post is the same with mine under similar conditions and someone in the comments suggested that it is about the system not being able to run cpython due to missing redistributable packages and such. I would appreciate if someone would be able to elaborate on that, because i think that might be the problem.

Thanks in advance!

2

There are 2 answers

0
Anthony Tuininga On

Taking a quick look at zipapp, I see that it assumes a pure Python application. The oracledb package contains extension modules (one of those is base_impl) and these cannot be loaded from inside a zip file. You will need to exclude oracledb from the your zipapp package and have that installed separately.

0
veysel On

Thanks for the answer Anthony, that seems to be the issue. If anyone is having the same problem, I solved the issue by using pyinstaller instead of pythons zipapp. Pyinstaller not only is able to handle oracledb library, it even includes its own python in the packet.