简体   繁体   中英

How can I create a Python standalone executable using Hy modules?

Given an entry file main.py like so:

#-*- coding: utf-8 -*-
# -*- mode: python -*-

import hy
import os.path
import hymodule

datas=[(os.path.dirname(hy.__file__), 'hy')]

hymodule.hello_world()

Given a Hy file hymodule.hy:

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

If I use pyinstaller to create a standalone file:

pyinstaller main.py --onefile 

And execute main.exe I get this error:

 $ ./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
  • Everything works fine if I execute main.py using python (without using pyinstaller).
  • Everything works fine if I change hymodule to be a Python module and use pyinstaller

What is the proper way to create a standalone executable using Hy modules?

PyInstaller support is not implemented for Hy. I don't know whether changes would be needed to PyInstaller, Hy, or both. You can always try hy2py ing all your code first, but this may not work if (a) your code still depends on Hy and (b) PyInstaller chokes on Hy even when used as an ordinary Python library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM