0

Ok, I developed a PySide desktop application and I wanted to share it using cx_Freeze. I had some problem packaging paramiko library but I resolved using this workaround.

Everything was working on my machine, meaning that double-clicking on the .exe generated by cx_Freeze the app was starting and working correctly.

The big disappointment arrived when I tested the package on my friend's PC.

The app didn't start and showed this error:

File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
  File "main_window.py", line 13, in <module>
  File "C:\Users\frpegora\Desktop\Projects\GUI\single_widget.py", line 13, in <module>
  File "C:\Users\frpegora\Desktop\Projects\GUI\importer_server.py", line 14, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\__init__.py", line 22, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\transport.py", line 90, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\ed25519key.py", line 20, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 7, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 71, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 195, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 142, in init_static_locks
ImportError: DLL load failed: The specified module could not be found.

The problem I thought to have solved was back again!

More precisely some time ago I passed the DLLs needed by paramiko using this workaround in the setup.py for cx_Freeze:

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))

build_exe_options = {"packages": ['cffi', 'cryptography'],
                     'include_files': [ os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libcrypto-1_1-x64.dll"),
                     os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libssl-1_1-x64.dll")]}

The problem is that as shown in the error I posted from my friend's PC, the program is looking for those DLLs on my PC's path!

Can you suggest a different solution? I tried everything included:

  • Passing the DLLs by hand
  • Copying the entire folder shown in the error

Here is my setup.py:

from cx_Freeze import setup, Executable 
import os.path

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))

build_exe_options = {"packages": ['cffi', 'cryptography'], 'include_files': [ ('libssl-1_1-x64.dll', os.path.join('lib', 'libssl-1_1-x64.dll')),
 ('libcrypto-1_1-x64.dll', os.path.join('lib', 'libcrypto-1_1-x64.dll'))]}


target = Executable(
    script="main_window.py",
    base = "Win32GUI",
    icon="images\\icon.ico"
    )

setup(name = "AppGen" , 
    version = "0.1" , 
    description = "" ,
    options={'build_exe': build_exe_options},
    executables = [target])
jpeg
  • 2,372
  • 4
  • 18
  • 31
Francesco Pegoraro
  • 778
  • 13
  • 33
  • Please consider using `code formatting` with backticks ` instead of **bold** to emphasize package names such as cx_Freeze and paramiko. – jpeg Jun 25 '19 at 12:52

1 Answers1

1

Looking on the GitHub repository of cryptography, the line causing the error seems to be:

__import__("_ssl")

Thus probably _ssl is missing on your friend's PC. Try to add

import _ssl

to your main script or to modify the build_exe_options in your setup script as follows:

build_exe_options = {"packages": ['cffi', 'cryptography'],
                     'include_files': [os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libcrypto-1_1-x64.dll"),
                                       os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libssl-1_1-x64.dll")],
                     'includes': ['_ssl']}

Regarding your statement:

The problem is that as shown in the error I posted from my friend's pc, the program is looking for those dlls on my PC's path!

You are probably mislead by the paths shown in the traceback: These are filenames attached to code objects which presumably do not get actualized when the frozen application is moved. See my answer to How to fix numpy dependencies path on a python 3.7.3 script on Linux frozen with cx_Freeze 6.0b1? for more details and a cx_Freeze option allowing the paths to be actualized at freezing.

jpeg
  • 2,372
  • 4
  • 18
  • 31
  • nice answer! I am gonna try it in a few days and let you know! – Francesco Pegoraro Jun 25 '19 at 13:13
  • Ok that wasn't the problem. I think it's probably that I am using cx_Oracle, an oracle client connector for python that requires that you have an oracle file in your environment path. So, I know how to include the file with cx_freeze but how to set the environment path? – Francesco Pegoraro Jun 28 '19 at 14:33
  • Have a look at [this answer](https://stackoverflow.com/a/47604770/8516269) by the developer of both cx_Oracle and cx_Freeze on a question regarding a similar issue with PyInstaller. – jpeg Jul 01 '19 at 06:29
  • Yes I know what I have to do to use cx_oracle, I'd like to know HOW to do it using python in the cx_freeze setup.py. – Francesco Pegoraro Jul 01 '19 at 11:01
  • If I understand correctly what you want you do and the linked answer, what you want to do is impossible. Either an Oracle client is already installed on the target machine and your frozen script will then work as well on that machine, or an Oracle client is not installed there, and there is no (legal) way for your installation script to also automatically install a licensed Oracle client on that machine. But maybe I misunderstand something, if you want to know more please ask a new question with a [example], your error message, and make sure to add the `cx-oracle` tag. – jpeg Jul 01 '19 at 11:24