我正在用pyInstaller创建一个应用程序,但它有一个致命错误。我正在使用这个包
从pynput.键盘导入控制器
有人知道如何修复pyInstaller和pynput的不兼容?也许我可以用一些pyInstaller的钩子?以及如何安装?
重要事实:
- 我在蟒蛇和spyder中使用python3.8
- 我的script.py执行成功
- 我创建了其他应用程序(没有pynput(,没有出现任何问题
- 我已经用pynput 1.7和1.6.8测试过了
- 我已经卸载并重新安装了PyInstall
这是警告文件:
missing module named _posixsubprocess - imported by subprocess (optional), multiprocessing.util (delayed)
<br>
missing module named pwd - imported by posixpath (delayed, conditional), shutil (optional), tarfile (optional), pathlib (delayed, conditional, optional), http.server (delayed, optional), webbrowser (delayed), netrc (delayed, conditional), getpass (delayed), distutils.util (delayed, conditional, optional)
<br>
missing module named posix - imported by os (conditional, optional), shutil (conditional)
<br>
missing module named resource - imported by posix (top-level), test.support (optional)
<br>
missing module named 'org.python' - imported by copy (optional), xml.sax (delayed, conditional)
<br>
missing module named _posixshmem - imported by multiprocessing.resource_tracker (conditional), multiprocessing.shared_memory (conditional)
<br>
missing module named multiprocessing.set_start_method - imported by multiprocessing (top-level), multiprocessing.spawn (top-level)
<br>
missing module named multiprocessing.get_start_method - imported by multiprocessing (top-level), multiprocessing.spawn (top-level)
<br>
missing module named grp - imported by shutil (optional), tarfile (optional), pathlib (delayed)
<br>
excluded module named _frozen_importlib - imported by importlib (optional), importlib.abc (optional), zipimport (top-level)
<br>
missing module named _frozen_importlib_external - imported by importlib._bootstrap (delayed), importlib (optional), importlib.abc (optional), zipimport (top-level)
<br>
missing module named multiprocessing.get_context - imported by multiprocessing (top-level), multiprocessing.pool (top-level), multiprocessing.managers (top-level), multiprocessing.sharedctypes (top-level)
<br>
missing module named multiprocessing.TimeoutError - imported by multiprocessing (top-level), multiprocessing.pool (top-level)
<br>
missing module named _scproxy - imported by urllib.request (conditional)
<br>
missing module named termios - imported by tty (top-level), getpass (optional)
<br>
missing module named 'java.lang' - imported by platform (delayed, optional), xml.sax._exceptions (conditional)
<br>
missing module named multiprocessing.BufferTooShort - imported by multiprocessing (top-level), multiprocessing.connection (top-level)
<br>
missing module named multiprocessing.AuthenticationError - imported by multiprocessing (top-level), multiprocessing.connection (top-level)
<br>
missing module named asyncio.DefaultEventLoopPolicy - imported by asyncio (delayed, conditional), asyncio.events (delayed, conditional)
<br>
missing module named vms_lib - imported by platform (delayed, conditional, optional)
<br>
missing module named java - imported by platform (delayed)
<br>
missing module named _winreg - imported by platform (delayed, optional)
<br>
missing module named console - imported by pyreadline.console.ansi (conditional)
<br>
missing module named startup - imported by pyreadline.keysyms.common (conditional), pyreadline.keysyms.keysyms (conditional)
<br>
missing module named sets - imported by pyreadline.keysyms.common (optional)
<br>
missing module named System - imported by pyreadline.clipboard.ironpython_clipboard (top-level), pyreadline.keysyms.ironpython_keysyms (top-level), pyreadline.console.ironpython_console (top-level), pyreadline.rlmain (conditional)
<br>
missing module named StringIO - imported by pyreadline.py3k_compat (conditional), six (conditional)
<br>
missing module named IronPythonConsole - imported by pyreadline.console.ironpython_console (top-level)
<br>
missing module named clr - imported by pyreadline.clipboard.ironpython_clipboard (top-level), pyreadline.console.ironpython_console (top-level)
<br>
missing module named org - imported by pickle (optional)
<br>
runtime module named six.moves - imported by pynput._util (top-level)
<br>
我读了很多关于隐藏导入的文章,并尝试了代码
pyinstaller --hidden-import=pynput.keyboard._win32 --hidden-import=pynput.mouse._win32 script.py
令人惊讶的是,它使.exe正常工作。对于其他类似的问题,我建议在这里和这里检查。此命令经过测试,可在Windows中使用。小小的改动也使它对Linux有用。
我失败的地方是我省略了选项";鼠标";因为我没有使用它。这些隐藏的导入是必要的。