如何使用 Hy 模块创建 Python 独立可执行文件?



给定一个条目文件 main.py 如下所示:

#-*- coding: utf-8 -*-
# -*- mode: python -*-
import hy
import os.path
import hymodule
datas=[(os.path.dirname(hy.__file__), 'hy')]
hymodule.hello_world()

给定一个 Hy 文件 hymodule.hy:

(defn hello-world []
(print "hello world!"))

如果我使用 pyinstaller 创建一个独立文件:

pyinstaller main.py --onefile 

并执行main.exe我收到此错误:

$ ./dist/main.exe
Traceback (most recent call last):
File "main.py", line 6, in <module>
import hymodule
ModuleNotFoundError: No module named 'hymodule'
[10852] Failed to execute script main
  • 如果我使用 python 执行 main.py(不使用 pyinstaller(,一切正常。
  • 如果我将hymodule更改为Python模块并使用pyinstaller,一切正常

使用 Hy 模块创建独立可执行文件的正确方法是什么?

PyInstaller 支持未针对 Hy 实现。我不知道是否需要对PyInstaller,Hy或两者进行更改。您可以随时尝试先hy2py所有代码,但如果(a(您的代码仍然依赖于Hy,并且(b(即使用作普通Python库,PyInstaller也会阻塞Hy,则这可能不起作用。

最新更新