How to get the current path of compiled binary from Python using Nuitka?

狂风中的少年 提交于 2020-01-04 06:15:07

问题


Nuitka is good at compiling Python to excutable binary. But the compiled binary finds other resource files from original absolute path. Thus, for moving to another computer requires to make the directory tree same as the original one.

For example, if I compile a project like this:

/home/me/myproj/
╠═ myprog.py
╚═ resource
   ╚═ foo.data

I should put the resulting binary and resource to the same location of another computer. How to solve this problem?

My simpler spike is:

# /home/me/myproj/spike.py
import os
print(os.path.dirname(__file__))

And after compiling it, moving to any other location, I always got the result of /home/me/myproj.

I need a result like /another/path if I move compiled myproj.bin to /another/path.

来源:https://stackoverflow.com/questions/59427353/how-to-get-the-current-path-of-compiled-binary-from-python-using-nuitka

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!