简体   繁体   English

Py2App找不到标准模块

[英]Py2App Can't find standard modules

I've created an app using py2app, which works fine, but if I zip/unzip it, the newly unzipped version can't access standard python modules like traceback, or os. 我使用py2app创建了一个应用程序,该应用程序运行良好,但是如果我压缩/解压缩该应用程序,则新解压缩的版本将无法访问标准Python模块(例如traceback或os)。 The manpage for zip claims that it preserves resource forks, and I've seen other applications packaged this way (I need to be able to put this in a .zip file). zip的手册页声称它保留了资源派生,并且我已经看到了其他以这种方式打包的应用程序(我需要能够将其放入.zip文件中)。 How do I fix this? 我该如何解决?

This is caused by building a semi-standalone version that contains symlinks to the natively installed files and as you say, the links are lost when zipping/unzipping unless the " -y " option is used. 这是由于构建了一个半独立的版本而导致的,该版本包含指向本机安装文件的符号链接,并且如您所说,除非使用“ -y ”选项,否则在压缩/解压缩时这些链接会丢失。

An alternate solution is to build for standalone instead, which puts (public domain) files inside the application and so survives zipping/unzipping etc. better. 另一种解决方案是改为为独立版本构建,它将(公共领域)文件放入应用程序中,从而可以更好地保留zip / unzipping等。 It also means the app is more resilient to changes in the underlying OS. 这也意味着该应用程序对基础操作系统的更改更具弹性。 The downside is that it is bigger, of course, and is more complicated to get it set up. 缺点是,它当然更大,并且设置起来更复杂。

To build a stand alone version, you need to install the python.org version which can be repackaged. 要构建独立版本,您需要安装可以重新打包的python.org版本。 An explanation of how to do this is here , but read the comments as there have been some changes since the blog post was written. 有关如何执行此操作的说明在此处 ,但是请阅读注释,因为自撰写博客文章以来已有一些更改。

使用zip -y ...来创建文件,同时保留符号链接。

You probably need to give it your full PYTHONPATH. 您可能需要为其提供完整的PYTHONPATH。

Depends on your os. 取决于您的操作系统。 Here's how to find out: 找出方法如下:

import os [or any other std module] os. 导入操作系统[或任何其他标准模块]操作系统。 file () 档案 ()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM