用于创建macOS应用程序的cx_Freeze编码

问题描述 投票:7回答:1

我正在尝试使用cx_Freeze创建一个独立的Python3 macOS应用程序,包括tkinter和selenium。我的项目中有三个文件:

  • tkinter_tab3.py(包含GUI)
  • user.txt(包含用户信息)
  • ver004.py(从tkinter_tab3.py调用并执行任务)

我创建了以下setup.py文件,其中tkinter_tab3.py是要转换为可执行文件的文件:

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = ['encodings'], excludes = [])
includefiles = ['user.txt', 'ver004.py']

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

executables = [
    Executable('tkinter_tab3.py', base=base, targetName = 'suprbotcho')
]

setup(name='suprbotcho',
      version = '1.0',
      description = 'test',
      options = dict(build_exe = buildOptions),
      executables = executables)

但是,当我运行$python3 setup.py build然后单击创建的可执行文件时,我在终端中收到此错误:

Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

另外,当我运行$python3 setup.py bdist.mac$python3 setup.py bdist.dmg时,我收到以下错误:

build/suprbotcho-1.0.app/Contents/MacOS/lib/numpy/core/lib/libnpymath.a(npy_math.o):
error: can't copy 'build/suprbotcho-1.0.app/Contents/MacOS/lib/numpy/core/lib/libnpymath.a(npy_math.o):': doesn't exist or not a regular file

我不明白我哪里出错了,因为我已经阅读了有关encodings问题的其他帖子,但是在尝试发布解决方案后我没有发现任何进展。

以下是每个python文件的导入:

tkinter_tab3.py

from tkinter import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import numpy as np
import time
from datetime import datetime
from threading import Timer
from ver004 import SuPrBoTcHo, InIt_UsEr

ver004.py

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import numpy as np
import time
from datetime import datetime
from threading import Timer
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import NoSuchElementException

如果我可以帮助解决这个特定的问题,那就太棒了。如果您有任何特殊问题,请随时告诉我。

(python版本:3.6.3)

macos python-3.x selenium tkinter cx-freeze
1个回答
4
投票

我有同样的问题。

解决方案是将cxfreeze升级到最新版本,即执行以下步骤 -

pip install -U cx_Freeze==6.0.b1
© www.soinside.com 2019 - 2024. All rights reserved.