python中compiled error,如何停止在py2exe中编译的Python程序显示ImportError:No Module names'ctypes'...

I was wondering if this might be a compilation error or if there is something I can do to stop it from displaying. I have made an argparse program for cmd. I compiled it with py2exe and when I run it, it exacutes the program properly but always gives this error before running the code:

Traceback (most recent call last):

File "boot_common.py", line 46, in

ImportError: No module named 'ctypes'

If it is something in my code, here is my script:

import argparse

import zipfile

import os

from contextlib import closing

def parse_args():

parser = argparse.ArgumentParser('ziputil '+\

'-m -f -p ')

parser.add_argument('-f', action="store", dest='files', type=str,

help='-f : Specify the files to be zipped, or the .zip to be unzipped.')

parser.add_argument('-m', action="store", dest='mode', type=str,

help='-m : Zip to zip files, UnZip, to unzip files, or ZipDir to zip entire directories.')

parser.add_argument('-p', action="store", dest='path', type=str, nargs='?', const=os.getcwd(),

help='-p : specify the path to unpack/pack to.')

return vars(parser.parse_args())

def unzipPackage(path, files):

with zipfile.ZipFile(files, "r") as z:

z.extractall(path)

def zipPackage(path, files):

files = files.split(', ')

zf = zipfile.ZipFile(path, mode='w')

try:

for file in files:

zf.write(file)

finally:

zf.close()

def zipdir(path, zip):

for root, dirs, files in os.walk(path):

for file in files:

zip.write(os.path.join(root, file))

dict = parse_args()

files = dict['files']

path = dict['path']

mode = dict['mode']

if mode == 'Zip':

zipPackage(path, files)

elif mode == 'UnZip':

unzipPackage(path, files)

elif mode == 'ZipDir':

zipf = zipfile.ZipFile(path, 'w')

zipdir(files, zipf)

zipf.close()

解决方案

This is caused by a bug in py2exe, it'll be fixed in next release. More Info

The solution is to add ctypes to bootstrap_modules in C:\Python34\Lib\site-packages\py2exe\runtime.py file (line 117).

...

# modules which are always needed

bootstrap_modules = {

# Needed for Python itself:

"ctypes",

"codecs",

"io",

"encodings.*",

}

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值