gpt4 book ai didi

python - cx_freeze 不导入外部模块

转载 作者:太空宇宙 更新时间:2023-11-04 06:05:54 26 4
gpt4 key购买 nike

我选择尝试使用 cx_freeze,它将我的简单 python 3.x 键盘记录器转换为 exe。我选择 cx_freeze 因为 py2exe 只是 python 2.x 我正在使用这个 setup.py 脚本编译我的代码。

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])

base = 'Console'

executables = [
Executable('logger.py', base=base, targetName = 'logger.exe')
]

setup(name='PyLogger',
version = '0.1',
description = 'A Simple Keylogger',
options = dict(build_exe = buildOptions),
executables = executables)

当我编译我的代码时,我是

try:
import pythoncom
except ImportError:
input("Import Error, pywin32 is not installed")

try:
import pyHook
except ImportError:
input("Import Error, pyHook is not installed")

我收到导入错误,提示未安装 pywin32 和 pyHook。如何将外部模块导入 cx_freeze.

编辑 - 我尝试更改 setup.py 以添加 includes 选项,但没有任何区别。

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = ['pyHook','pythoncom'],includes = ['pyHook','pythoncom'], excludes = [])

base = 'Console'

executables = [
Executable('logger.py', base=base, targetName = 'logger.exe')
]

setup(name='PyLogger',
version = '0.1',
description = 'A Simple Keylogger',
options = dict(build_exe = buildOptions),
executables = executables)

最佳答案

找到外部模块的.pyd文件。将其复制并粘贴到构建文件中。因此,例如,如果它正在寻找 _cpyHook(我和你有同样的问题,它说模块丢失),请转到 C:\Python33\Lib\site-packages\pyHook 并将文件复制并粘贴到 C :\Python33\build\exe.win-amd64-3.3.

关于python - cx_freeze 不导入外部模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22074774/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com