cryptography and pyinstaller (not using Fernet) error
13:55 09 Jul 2025

I'm using pyinstaller main2.spec command. The main2.spec file is the next:

# -*- mode: python ; coding: utf-8 -*-


a = Analysis(
    ['main.py'],
    pathex=[],
    binaries=[],
    datas=[
        ('./backend', 'backend'),
        ('./classes', 'classes'),
        ('./common', 'common'),
        ('./functions', 'functions'),
        ('./sql', 'sql'),
        ('./interfaces', 'interfaces')
    ],
    hiddenimports=['cryptography.hazmat.primitives.kdf.pbkdf2', 'uuid'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
)
pyz = PYZ(a.pure)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.datas,
    [],
    icon='./logo.ico',
    name='CREDTI',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)

It generates a CREDTI.exe file. When i execute the file and click a button that get data from a oracle database, it give me the next error:

Traceback (most recent call last):
File "main.py", line 164, in send_mail_if
File "backend\login.py", line 16, in login
File "sql\sql.py", line 44, in select_all_fields_with_where
File "sql\sql.py", line 9, in create_connection
File "oracledb\connection.py", line 1194, in connect
File "oracledb\connection.py", line 575, in __init__
File "src\\oracledb\\impl/thin/connection.pyx", line 318, in oracledb.thin_impl.ThinConnImpl.__init__
File "src\\oracledb\\impl/thin/connection.pyx", line 78, in oracledb.thin_impl.BaseThinConnImpl.__init__
File "oracledb\errors.py", line 195, in _raise_err
oracledb.exceptions. NotSupportedError: DPY-3016: python-oracledb thin mode cannot be used because the cryptography package is not installed

I read that the error would be fixed adding "from cryptography.hazmat.primitives.kdf import pbkdf2" and "import encodings.idna" in imports, but it works with Fernet and i'm not using that. I still tried, adding in main.py and sql.py files, but it didn't work.

I'm using the following versions:

cryptography 44.0.1
oracledb     2.5.1
pyinstaller  6.12.0

I have another project with those versions, but I have no errors there.

python cryptography pyinstaller python-oracledb