我的 python 脚本与 python3 命令完美运行。 我使用
cython main.py --embed
将我的python文件转换为c文件
它输出 c 文件和这个:
/usr/lib/python3.11/site-packages/Cython/Compiler/Main.py:381: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /home/solid/PythonAuthenticator/main.py tree = Parsing.p_module(s, pxd, full_module_name)
然后我用来将其转换为二进制文件
PYTHONLIBVER=python$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')$(python3-config --abiflags) gcc -Os $(python3-config --includes) main.c -o pyauth $(python3-config --ldflags) -l$PYTHONLIBVER
但是当我运行二进制文件时,输出:
Traceback (most recent call last):
File "main.py", line 87, in init main
key_id: str = typer.Argument(None),
TypeError: Expected str, got ArgumentInfo
这是第 87 行函数的一部分(我在这个程序中使用 Typer):
@app.command()
def show_code(
key_id: str = typer.Argument(None),
issuer_name: str = typer.Option(None),
e: bool = typer.Option(False, help="Show TOTP code of a key outside key file.")
):
...
我使用了 pyinstaller,它可以工作,但是二进制文件太大而且速度很慢,我不知道我应该做什么
DavidW 的评论有帮助:
区别在于,默认情况下,Cython 会检查注释的类型,因此它们必须正确。您可以使用
指令将其关闭。annotation_typing
我将其添加到文件的开头,现在它可以工作了:
#cython: annotation_typing = False
#cython: language_level=3
我将制作一个
setup.py
以获得更有条理的代码。