首页 > 解决方案 > Cx_freeze:如何解决由多个同名 .dylib 文件引起的冲突

问题描述

我已经创建了一个 python 应用程序,现在我想将它变成一个独立的应用程序。我正在使用来自 virtualenv 的 cx_freeze,它以前在我的机器上使用具有较少依赖性的脚本工作。

我目前遇到了一个问题,当它尝试将名称相同的 dylib 文件复制到构建文件夹时出现 cx_freeze 错误。

我正在运行命令:

python3 setup.py build

我的 setup.py 文件如下所示:

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)

这是我得到的错误:

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

如果我排除引入与另一个 dylib 冲突的库(请参阅 setup.py 中已注释掉的排除构建选项),则该命令将成功运行,但我构建的应用程序将由于缺少依赖项而失败。

有谁知道解决这个问题的方法?

如果重要的话,还有一些其他信息->

操作系统: Mac OS Big Sur
Python 版本: 3.7.8
cx_freeze 版本: 6.2

标签: pythonpython-3.xcx-freeze

解决方案


在这个 cx_Freeze问题中似乎已经报告了这个同名错误,由这个拉取请求引入,它在将第二个文件复制到另一个文件的路径时引发错误。

合并了一种解决方法以打印警告并仅使用文件的第一个副本而不是引发错误。由于它似乎还没有发布(截至 2021 年 3 月 9 日,v6.5.3),我从 Git 安装了 cx_Freeze(在克隆并进入 repo 之后,我安装了它pip install -e .),运行cxfreeze,并看到了这样的警告像这样:

*** 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.

其中冲突文件被简单地跳过,允许构建继续进行。


推荐阅读