Py2exe向exe添加包(例如Carbon)

时间:2017-02-09 08:18:09

标签: python python-2.7 py2exe paramiko

我创建了一个脚本,我使用了这个导入:

import MySQLdb
import sys
import paramiko as pm
import os

现在我尝试使用py2exe和此setup.py:

将此脚本转换为.exe
# setup.py 
from distutils.core import setup
import os
import MySQLdb
import sys
import paramiko
import py2exe

data_files = []
setup(
    name='Worker',
    console=['Script.py'], 
    options={ 
        'py2exe': {
            'packages': [],
            'dist_dir': 'dist', 
            'compressed': True, 
            'includes': ['paramiko', 'MySQLdb'], 
        }
    },

    data_files=data_files 

)

如果我运行设置,则部分来自日志:

The following modules appear to be missing
['Carbon', 'Carbon.Files', '_imp', '_scproxy', '_sysconfigdata', '_thread', 'builtins', 'cryptography.hazmat.bindings._commoncrypto', 'gssapi', 'importlib.machinery', 'pkg_resources.extern.appdirs', '
pkg_resources.extern.packaging', 'pkg_resources.extern.six', 'pkg_resources.extern.six.moves', 'sspi', 'sspicon', 'win32pipe', 'winreg']

*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.

它创建了一个exe,但如果我尝试运行它,我会得到模块缺失的错误。 那么如何将这些模块添加到我的exe / setup.py中呢?

2 个答案:

答案 0 :(得分:1)

尝试运行此代码:

setup.py

from distutils.core import setup
import os
import MySQLdb
import sys
import paramiko
import py2exe

data_files = []
setup(
    name='Worker',
    console=['Script.py'], 
    options={ 
        'py2exe': {
            'packages': ['Carbon', 'Carbon.Files', '_imp', '_scproxy', '_sysconfigdata', '_thread', 'builtins', 'cryptography.hazmat.bindings._commoncrypto', 'gssapi', 'importlib.machinery', 'pkg_resources.extern.appdirs', ' pkg_resources.extern.packaging', 'pkg_resources.extern.six', 'pkg_resources.extern.six.moves', 'sspi', 'sspicon', 'win32pipe', 'winreg'],
            'dist_dir': 'dist', 
            'compressed': True, 
            'includes': ['paramiko', 'MySQLdb'], 
        }
    },

    data_files=data_files 

)

我从Answer获取了参考资料。

答案 1 :(得分:0)

我有类似的问题。据我所知,Carbon需要“石墨”,而这仅是* nix!因此,使用py2exe在Windows上无法轻松解决任何问题。