0

我有一个 Python 脚本(作为入口点)、一个Hy库(只需添加两列)和一个输入数据文件:

$ cat add_cols/app.py 
import hy
import sys
from mylib import add2col

def main():
    inp = sys.argv[1]
    out = sys.argv[2]
    print(f'read file {inp}, and convert to file {out}')
    add2col(inp, out)

if __name__ == '__main__':
    main()

$ cat add_cols/mylib.hy 
(import [pandas :as pd])

(defn add2col [inpfile outfile]
  (setv inp (.read_csv pd inpfile))
  (assoc inp "cola"  (+ (get inp "cola") (get inp "colb")))
  (.to_csv inp outfile :index False))

$ cat demo.csv
cola,colb
1,2
1,2
1,2
1,2
1,2
1,2
1,2
1,2
1,2
1,2

我可以直接运行它并得到结果:

$ cd add_cols
$ python app.py ../demo.csv res.csv
read file ../demo.csv, and convert to file res.csv
$ cat res.csv
cola,colb
3,2
3,2
3,2
...

现在我尝试将它作为zipapp运行:

$ python -m zipapp add_cols -m 'app:main'
$ python add_cols.pyz demo.csv res.csv
Traceback (most recent call last):
  File "/home/leo/apps/miniconda3/envs/hylang/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/leo/apps/miniconda3/envs/hylang/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "add_cols_hy.pyz/__main__.py", line 2, in <module>
  File "add_cols_hy.pyz/app.py", line 3, in <module>
ModuleNotFoundError: No module named 'mylib'

为什么mylib加载不出来?如何在 zipapp 中加载 Hy 库?

环境:

  • Anaconda 中的 Python 3.6

  • Ubuntu 16.04

谢谢!

4

1 回答 1

0

是的,这是一个错误。现在是Hy 的问题 #1774

于 2019-08-03T14:14:52.270 回答