Francesco Pegoraro
Francesco Pegoraro

Reputation: 808

cx_Freeze package doesn't work on another machine

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:

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])

Upvotes: 0

Views: 950

Answers (1)

jpeg
jpeg

Reputation: 2461

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.

Upvotes: 1

Related Questions