You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
最近在学习Rust并使用PyO3创建独立二进制文件(exe)
以下是遇到的问题的解决方案以及疑问
代码如下
1, 需要将
python3x.dll
与.exe
文件放置在同一目录下2,
runtime
存放python.exe
的目录3,
scripts
你的python代码存放目录4,
site-packages
第三方包存放目录5,
runtime/python310.zip
使用嵌入式python解释器(如:python-3.10.10-embed-amd64)时需要设置。(后面会给出说明)目录结构
此时的
PATH
如下:经过测试PyO3在编译时会默认添加一部分路径(排除前面三个路径),所以在使用嵌入式解释器(如:python-3.10.10-embed-amd64)时需要配置
runtime/python310.zip
,当然你也可以将python310.zip
复制到.exe
同级目录(即满足D:\\CNWei\\CNW\\test_pyo3\\python310.zip
)。示例中的目录结构与设置可以满足将程序分发给没有安装python的机器使用。
猜测:
1,上面提到的PyO3编译时默认添加的路径或许就是为什么python解释器没有去.venv查找第三方包的原因。
疑问:
1,另外在很多讨论中提到了
PYO3_PYTHON
,我不明白他的工作原理,我认为它可以使编译后的.exe
脱离python3x.dll
工作,但实际并不满足期望,希望各位能给出示例科普一下。Beta Was this translation helpful? Give feedback.
All reactions