The keyring module is not enabled during packaging with py2exe

I am making an application using python 2.7 on windows and keyring-3.2.1 . In my python code on eclipse I used

import keyring keyring.set_password("service","jsonkey",json_res) json_res= keyring.get_password("service","jsonkey") 

works fine as i save json response in keyring. But, when I converted python code to exe using py2exe, it shows import bracketing when creating dist. Suggest how to enable keyring in py2exe.

 Traceback (most recent call last): File "APP.py", line 8, in <module> File "keyring\__init__.pyc", line 12, in <module> File "keyring\core.pyc", line 15, in <module> File "keyring\util\platform_.pyc", line 4, in <module> File "keyring\util\platform.pyc", line 29, in <module> AttributeError: 'module' object has no attribute 'system' 

Platform Code:

 from __future__ import absolute_import import os import platform def _data_root_Windows(): try: root = os.environ['LOCALAPPDATA'] except KeyError: # Windows XP root = os.path.join(os.environ['USERPROFILE'], 'Local Settings') return os.path.join(root, 'Python Keyring') def _data_root_Linux(): """ Use freedesktop.org Base Dir Specfication to determine storage location. """ fallback = os.path.expanduser('~/.local/share') root = os.environ.get('XDG_DATA_HOME', None) or fallback return os.path.join(root, 'python_keyring') # by default, use Unix convention data_root = globals().get('_data_root_' + platform.system(), _data_root_Linux) 

.Py platform code:

 import os import sys # While we support Python 2.4, use a convoluted technique to import # platform from the stdlib. # With Python 2.5 or later, just do "from __future__ import absolute_import" # and "import platform" exec('__import__("platform", globals=dict())') platform = sys.modules['platform'] def _data_root_Windows(): try: root = os.environ['LOCALAPPDATA'] except KeyError: # Windows XP root = os.path.join(os.environ['USERPROFILE'], 'Local Settings') return os.path.join(root, 'Python Keyring') def _data_root_Linux(): """ Use freedesktop.org Base Dir Specfication to determine storage location. """ fallback = os.path.expanduser('~/.local/share') root = os.environ.get('XDG_DATA_HOME', None) or fallback return os.path.join(root, 'python_keyring') # by default, use Unix convention data_root = globals().get('_data_root_' + platform.system(), _data_root_Linux) 
+7
json python py2exe python-keyring mercurial-keyring
source share
1 answer

The problem you are reporting is related to an environment that contains invalid modules, possibly due to improper installation of one version of keyring over another. You will want to make sure that you delete the remnants of the old version of the keyring. In particular, make sure that your sites do not have a file named keyring \ util \ platform. *.

However, after that you will encounter another problem. Keyring programmatically loads its server modules , so py2exe will not detect them.

To get around this, you need to add the "package" declaration to your py2exe options to enable the keyring.backends package. I called the following setup.py script with Python 2.7 to convert 'app.py' (which imports keyring) to exe:

 from distutils.core import setup import py2exe setup( console=['app.py'], options=dict(py2exe=dict( packages='keyring.backends', )), ) 

As a result, app.exe will import and call keyring.

+6
source share

All Articles