Cx_freeze: How do I resolve conflicts caused by multiple .dylib files having the same name

Viewed 536

I have created a python application that I now want to make into a standalone application. I am using cx_freeze from a virtualenv, which has worked before on my machine with scripts that have less dependencies.

I am currently running into an issue where cx_freeze errors when it tries to copy dylib files that are named the same to the build folder.

I am running the command:

python3 setup.py build

My setup.py file looks like:

from cx_Freeze import setup, Executable

build_options = {'packages': ["PySimpleGUI", "matplotlib", "pandas", "descartes", "geopandas", "cities_coordinates"],
                 #'excludes': ["PIL", "pyproj", "setuptools"],
                 "zip_exclude_packages": [],}

import sys
base = 'Win32GUI' if sys.platform=='win32' else None

executables = [
    Executable('main.py', base=base, targetName = 'data_visualizer')
]

setup(name='data_visualizer',
      version = '0.1',
      description = 'Data visualization tool',
      options = {'build_exe': build_options},
      executables = executables)

This is the error I am getting:

...
copying /Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/fiona/.dylibs/libproj.12.dylib -> build/exe.macosx-10.9-x86_64-3.7/libproj.12.dylib
copying /Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/fiona/.dylibs/libjson-c.2.dylib -> build/exe.macosx-10.9-x86_64-3.7/libjson-c.2.dylib
Traceback (most recent call last):
  File "setup.py", line 18, in <module>
    executables = executables)
  File "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/cx_Freeze/dist.py", line 392, in setup
    distutils.core.setup(**attrs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/cx_Freeze/dist.py", line 260, in run
    freezer.Freeze()
  File "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/cx_Freeze/freezer.py", line 788, in Freeze
    self._WriteModules(fileName, self.finder)
  File "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/cx_Freeze/freezer.py", line 712, in _WriteModules
    relativeSource=True,
  File "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/cx_Freeze/freezer.py", line 231, in _CopyFile
    resolvedPath=dependent_file
  File "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/cx_Freeze/freezer.py", line 231, in _CopyFile
    resolvedPath=dependent_file
  File "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/cx_Freeze/freezer.py", line 173, in _CopyFile
    sourcePath=normalizedSource, targetPath=normalizedTarget
  File "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/cx_Freeze/darwintools.py", line 446, in getDarwinFile
    raise DarwinException(exceptionString)
cx_Freeze.darwintools.DarwinException: Attempting to copy two files to "build/exe.macosx-10.9-x86_64-3.7/libwebp.7.dylib"
   source 1: "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/PIL/.dylibs/libwebp.7.dylib" (real: "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/PIL/.dylibs/libwebp.7.dylib")
   source 2: "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/fiona/.dylibs/libwebp.7.dylib" (real: "/Users/AidenTheJaunty/projects/test/lib/python3.7/site-packages/fiona/.dylibs/libwebp.7.dylib")
(This may be caused by including modules in the zip file that rely on binary libraries with the same name.)

If I exclude libraries that introduce a dylib that conflicts with another (see commented out excludes build option in the setup.py) then the command will run successfully, but my built application will fail because of missing dependencies.

Does anyone know of a way to get around this issue?

Some other info if it matters ->

Operating System: Mac OS Big Sur
Python Version: 3.7.8
cx_freeze version: 6.2

1 Answers

This same name error appears to have been reported in this cx_Freeze issue, introduced by this pull request that raises an error when copying a second file onto the path of another.

A workaround was merged to print a warning and simply use the first copy of the file rather than raising an error. As it doesn't appear to have been released yet (as of 2021-03-09, v6.5.3), I installed cx_Freeze from Git (after cloning and entering the repo, I installed it by pip install -e .), ran cxfreeze, and saw warnings such as this:

*** WARNING ***
Attempting to copy two files to '../distcx/libopenblas.0.dylib'
source 1: '/venv/lib/python3.6/site-packages/numpy/.dylibs/libopenblas.0.dylib' (real: '/venv/lib/python3.6/site-packages/numpy/.dylibs/libopenblas.0.dylib')
source 2: '/venv/lib/python3.6/site-packages/scipy/.dylibs/libopenblas.0.dylib' (real: '/venv/lib/python3.6/site-packages/scipy/.dylibs/libopenblas.0.dylib')
(This may be caused by including modules in the zip file that rely on binary libraries with the same name.)
Using only source 1.

where the conflicting file was simply skipped, allowing the build to proceed.

Related