我正在尝试使用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)
答案 0 :(得分:4)
我遇到了同样的问题。
解决方案是将cxfreeze升级到最新版本,即执行以下步骤 -
pip install -U cx_Freeze==6.0.b1