6

我正在用 python 制作一个需要存储密钥的应用程序。我使用密钥环模块来存储密钥。我正在使用 python-2.7 和 osx 10.8.5 和密钥环 3.2(easy_install 密钥环)。代码在 Eclipse 上运行良好,但是当我使用 py2app 将代码转换为应用程序时,它显示错误 MYAPP Error open console Terminate

import keyring
keyring.set_password("title","section","keys")
res= keyring.get_password("title","section")

我在通过 py2app 制作 dist 时键入“python setup.py py2app”时包含了终端响应报废

byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/__init__.py to keyring/__init__.pyc
creating /Users/fis/Desktop/build/bdist.macosx-10.8-intel/python2.7-semi_standalone/app/collect/keyring
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/backend.py to keyring/backend.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/core.py to keyring/core.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/errors.py to keyring/errors.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/getpassbackend.py to keyring/getpassbackend.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/py27compat.py to keyring/py27compat.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/util/__init__.py to keyring/util/__init__.pyc
creating /Users/fis/Desktop/build/bdist.macosx-10.8-intel/python2.7-semi_standalone/app/collect/keyring/util
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/util/platform_.py to keyring/util/platform_.pyc
byte-compiling /Library/Python/2.7/site-packages/keyring-3.2-py2.7.egg/keyring/util/properties.py to keyring/util/properties.pyc
byte-compiling /Library/Python/2.7/site-packages/pathtools-0.1.2-py2.7.egg/pathtools/__init__.pyc to pathtools/__init__.pyc
creating /Users/fis/Desktop/build/bdist.macosx-10.8-intel/python2.7-semi_standalone/app/collect/pathtools
4

3 回答 3

1

不确定你是否解决了这个问题,但我在我的 Mac 上遇到了类似的问题(使用 python v2.7.6 和 py2app v0.9):脚本从命令行运行良好(即,python scriptname.py),但是当我用来py2app转换它时到 a .app,它失败了。

控制台消息使我得出结论,py2app它不够聪明,无法包含模块中的子keyring.backends模块。所以我明确地在那里导入了所有东西,它终于奏效了:

import keyring.backends.file
import keyring.backends.Gnome
import keyring.backends.Google
import keyring.backends.kwallet
import keyring.backends.multi
import keyring.backends.OS_X
import keyring.backends.pyfs
import keyring.backends.SecretService
import keyring.backends.Windows
import keyring

我希望这可以帮助你!

于 2015-03-08T03:24:58.550 回答
0

在 setup.py 中包含 packages='keyring.backends'以包含所有密钥环包。

于 2015-03-09T05:46:24.080 回答
0

我没有可能在本地尝试这个,这是我最好的猜测:

尝试在应用程序中导入您实际需要的所有位,包括在“正常”执行期间不会发生的异常

import keyring
import keyring.set_password as _unused_1
import keyring.backend
import keyring.backend.PasswordSetError as _unused_2

您可能还需要在运行时使用其他一些包,以进行检查,请执行以下操作:

$ python2.7
Python 2.7.5 (default, Sep  6 2013, 09:55:21) 
[GCC 4.8.1 20130725 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> before = sys.modules.keys()
>>> import keyring
>>> middle = sys.modules.keys()
>>> keyring.set_password("a", "b", "c")
Please set a password for your new keyring
Password: 
Password (again): 
Please input your password for the keyring
Password: 
>>> after = sys.modules.keys()
#
# now the interesting bits
#
>>> set(after).difference(set(middle))
set(['struct', 'crypt', 'base64', 'binascii', 'keyring.crypt', 'encodings.base64', 'encodings.base64_codec', '_struct'])
#
# and this
#
>>> set(middle).difference(set(before))
set(['cStringIO', 'heapq', 'logging.threading', 'sre_compile', '_collections', 'logging.cStringIO', '_sre', 'getpass', 'atexit', 'keyring.backend', 'logging.os', 'operator', 'Crypto.Cipher.AES', 'logging.traceback', 'keyring.os', '_heapq', 'logging.time', 'keyring.ConfigParser', 'logging.weakref', 're', 'keyring.getpass', 'sre_constants', 'imp', 'logging.codecs', 'collections', 'logging.thread', 'keyring.imp', 'keyring.logging', 'keyring.keyring', 'string', 'keyring.util.re', 'time', 'Crypto', 'termios', 'keyring.util.escape', 'logging', 'logging.atexit', 'keyring.util', 'logging.sys', 'keyring.abc', 'Crypto.Cipher', 'ConfigParser', 'keyring.util.string', 'keyring.getpassbackend', 'keyword', 'thread', 'strop', 'traceback', 'keyring', 'weakref', 'threading', 'itertools', 'keyring.Crypto', 'keyring.sys', 'sre_parse', 'logging.warnings', 'keyring.core'])

你会看到有多少模块被引入import keyring,但也有更多的模块被引入keyring.set_password(...)

现在,其中大部分应该是自动的py2app,但是可能会丢失一些运行时依赖项。

这背后的原因是py2app当它决定要包含哪些模块时会做一些棘手的事情。假装keyring.set_password()在这个阶段实际上并没有运行。事实上,如果它确实并且set_password必须有副作用,你会期望py2app打包一个普通的或修改过的模块吗?

于 2013-11-18T11:12:52.920 回答