码迷,mamicode.com
首页 > Web开发 > 详细

py2exe error: "ImportError: No module named httplib"

时间:2015-05-07 16:53:10      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:python   py2exe   

写了一个python程序(python2.7),用py2exe打包成一个native exe,结果老是报错

Traceback (most recent call last):
  File "p4_ticket_auth_jenkins.py", line 7, in <module>
  File "zipextimporter.pyc", line 82, in load_module
  File "jenkins\__init__.pyc", line 54, in <module>
  File "six.pyc", line 199, in load_module
  File "six.pyc", line 113, in _resolve
  File "six.pyc", line 80, in _import_module
ImportError: No module named httplib

乍一看,貌似是py2exe打包时没有把httplib打包进去。

File "p4_ticket_auth_jenkins.py", line 7是import jenkins,看来是jenkins的lib导入出的问题。于是把python程序的逻辑部分删掉

import sys
import argparse
import logging
import jenkins
import xml.etree.ElementTree as ET
import time
import os
from subprocess import Popen, PIPE, STDOUT
import subprocess
import commands
import socket
import datetime

def main():
    print("asdf")
    

if __name__=="__main__":
    main()
再用打包,运行打包后的exe,报错缺httplib。在python源码中import httplib,还报错缺urllib。import urllib,搞定

import sys
import argparse
import logging
import jenkins
import xml.etree.ElementTree as ET
import time
import os
from subprocess import Popen, PIPE, STDOUT
import subprocess
import commands
import socket
import datetime
import httplib
import urllib2

def main():
    print("asdf")
    

if __name__=="__main__":
    main()


附上setup.py的代码:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
    console = [{'script': "test.py"}],
    zipfile = None,
)

这个setup.py可以把python代码(test.py)打包成native exe(不需要任何其他库的支持就能直接在windows上运行)。一条命令实现打包:

setup.py py2exe




py2exe error: "ImportError: No module named httplib"

标签:python   py2exe   

原文地址:http://blog.csdn.net/ybdesire/article/details/45560733

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!