cx_Freeze 和 PYC/PYD 文件

发布于 2024-09-02 06:22:39 字数 211 浏览 2 评论 0原文

我正在使用 cx_Freeze 冻结我的 python 程序。运行 cx_Freeze 时,会创建一堆 PYD 文件,一大堆 PYC 文件被放入名为library.zip 的存档中,还有一些 DLL 文件也在那里。

有人能告诉我 PYC 和 PYD 文件之间的区别吗? PYD 文件不在library.zip 中的原因是什么? 是否也可以将 PYD 文件放入存档中?

谢谢。

I'm using cx_Freeze to freeze my python program. On running cx_Freeze, a bunch of PYD files are created, a whole bunch of PYC files are put into a archive named library.zip and a few DLL files are there too.

Could someone tell me the difference between the PYC and the PYD files?
What's the reason for the PYD files not in the library.zip?
Is it possible to put the PYD files into the archive as well?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离线来电— 2024-09-09 06:22:39

免责声明:我有一段时间没有使用 cx_Freeze.......

PYD 文件是 DLL 机器代码文件,其中包含特定的 python 所需函数。

.PYC 文件是已编译为字节码的 .py 文件。

所以 PYD 是机器代码,PYC 是字节码

现在至于为什么 PYD 不在 .zip 中......我想这是因为 python 解释器需要这些 .PYD 来运行程序。 cx_Freeze 的作用基本上是这样的:

  1. 编译所有 .py 文件并将 .pyc 文件放入 zip 文件中
  2. 将所有需要的 .pyd 文件放入 zip 文件中
  3. 创建一个存根 .py 文件并将其放入输出目录中
  4. 复制 python.exe 并重命名 到 myprogram.exe 中
  5. 将打开 .zip 并运行内容所需的所有 .pyd 文件复制

,因此您实际上并没有编译 python 文件,而是重命名解释器并冻结所有源文件。

我希望这有帮助。

Disclaimer: I haven't used cx_Freeze in awhile......

.PYD files are DLL machine-code files that contain specific python-required functions.

.PYC files are .py files that have been compiled into bytecode.

so PYDs are machine code and PYCs are bytecode

Now as for why the PYDs aren't in the .zip....I'd imagine it's because those .PYDs are needed by the python interpreter to run the program. What cx_Freeze does is basically this:

  1. compile all .py files and throw the .pyc files in a zip
  2. put all needed .pyd files in the zip
  3. create a stub .py file and put it in the output directory
  4. copy the python.exe and rename to myprogram.exe
  5. copy all .pyd files needed to open the .zip and run the contents

So you're not actually compiling your python file, you're instead renaming the interpeter and freezing all the source files.

I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文