题python cx_freeze问题ascil [英] python cx_freeze problem ascil

查看:69
本文介绍了题python cx_freeze问题ascil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 py2exe cx_freeze 制作EXE文件。

I want to make EXE file by use py2exe or cx_freeze.

所以我尝试用py2exe制作exe文件,但是没有运气。

so I was try to make exe file with py2exe but no luck.

所以现在我用 cx_freeze ,但也失败了。

so now I was test with cx_freeze but it also failed.

如果有人可以帮助我很多帮助

if anyone can help me much apprecaite

以下是设置步骤 cx_freeze
中的.py文件来自 cx_Freeze 导入设置,可执行文件

following is setup.py file in cx_freeze from cx_Freeze import setup, Executable

copyDependentFiles=True
silent = True
includes = ["lxml", "lxml._elementpath", "lxml.etree", "gzip", "encodings.cp949", "encodings.utf_8", "encodings.ascii"]
setup(name='gearfacts',

     options = {
       "build_exe" : {
           "includes": includes,
           },
       },
     executables=[Executable('test.py')],
     ) 

以下是我的脚本源文件。

following is my script source file.

import lxml,cookielib,urllib,configobj,sys,getopt,string,mechanize,time,os 
from lxml import etree
from lxml.html import parse, fromstring
import sys, getopt, string  
import lxml.html
import encodings.utf_8
import encodings.euc_kr 
import encodings.cp949

br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# Want debugging messages?
br.set_debug_http(False)
br.set_debug_redirects(False)
br.set_debug_responses(False)

# User-Agent (this is cheating, ok?)
br.addheaders = [('User-agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)')]

SAVEFILE= 'betextract.txt'
post_count = 0
mac = ''
def getMacAddress():
      if sys.platform == 'win32':
     for line in os.popen("ipconfig /all"):
    if line.lstrip().startswith('Physical Address'):
   mac = line.split(':')[1].strip().replace('-',':')
   break
      else:
     for line in os.popen("/sbin/ifconfig"):
    if line.find('Ether') > -1:
   mac = line.split()[4]
   break
      return mac 
      print mac
getMacAddress()
print mac
def safeunicode(s):
      s = str(s).decode('utf-8')
      try:
     return s.encode('euc-kr').decode('cp949')
      except UnicodeDecodeError:
     return s

#check_demo()
#from configobj import ConfigObj Template 화일 불러오기 ini
config = configobj.ConfigObj('config.ini')
section1 = config['NAVERPASS']
section2 = config['NAVERID']
section3 = config['Nblogkeyword']
section4 = config['end_line']
section5 = config['Content']
section6 = config['HongboSubject']
section7 = config['HongboBody']

NAVERPASS     = section1['NAVERPASS']
NAVERID       = section2['NAVERID']
Nblogkeyword  = section3['Nblogkeyword']
end_line       = section4['end_line']
Content       = section5['Content']
HongboSubject = section6['HongboSubject']
HongboBody    = section7['HongboBody']

enkw = str(Nblogkeyword).decode('cp949')

#아래부분에서 빼기를 위한 int로 변환
end_line       = int(section4['end_line'])
start_line = 0
while end_line: 
    #end_line = end_line - 9
    form = {
        'where': 'post',
        'sm' : 'ab_pge',
        'query' : enkw,
        'st' : 'sim',
        'date_option' : '-1',
        'date_from' : '',
        'date_to' : '',
        'dup_remove' : '1',
        'post_blogid' : '',
        'post_blogurl' : '',
        'post_blogurl_without' : '',
        'detail_and_query' : '',
        'detail_not_query' : '',
        'detail_or_query' : '' ,
        'detail_udp_query' : '',
        'srchby' : 'all',
        'nso' : 'so%3Ar%2Ca%3Aall%2Cp%3A',
        'ie' : 'utf8',
        'start' : start_line
      }
    qstring = urllib.urlencode(form)
    f = urllib.urlopen('http://cafeblog.search.naver.com/search.naver?%s' %qstring)
    html = f.read()
    f.close()
    start_line += 10
    end_line = end_line - 10
    s= []
    html = lxml.html.fromstring(html)
    save = open(SAVEFILE, 'w+')
    for content in html.cssselect('li.sh_blog_top'):
        try:
            subject = content.cssselect('dl dt a.sh_blog_title b')[0].text_content()
            body = content.cssselect('dl dd.sh_blog_passage')[0].text_content()
            print u'[+추출중+] %s | %s ' %(subject , body)

            chen = '%s|%s' %(subject, body)  #중요 이런식으로 처리를 해야함 꼭 인코딩!
            title2 = chen.encode('cp949')
            save.write(title2 + '\n')            
        except Exception, err:
            sys.stderr.write(u'에러발생 => 에러 자동처리중... %s\n' % str(err))
            content = ''
            break


    save.close()
    #print  subject  , body
    #s.append(subject)
    #s.append(body)
    #print '|'.join(s)


## Show the response headers
#print br.info()
## or
##print br.response().info()
#for link in br.links():
    #print link
br.open('http://nid.naver.com/nidlogin.login')
#for f in br.forms():
    #print f

br.select_form(nr=0)
br.form['id']=NAVERID
br.form['pw']=NAVERPASS
#br.click(type="submit", nr=0)
#print br.forms()
#br.submit(name="URL", nr=0)
#html = br.response().read()
#print html
br.form.action='https://nid.naver.com/nidlogin.login'    #javascript source analysis!! have to find inside javascript source
br.submit()
html = br.response().read()
#decoded = br.response().read().decode('utf-8')
#print html
br.open('http://m.blog.naver.com/')
save = open(SAVEFILE)
for line in save:
    sub = line.split('|')[0]
    con = line.split('|')[1].replace('\n', '')
    #print sub, con

    br.open('http://m.blog.naver.com/PostWriteForm.nhn?blogId=ylgwn&categoryNo=')
    #print br.response().read()    
    #for f in br.forms():
        #print f   
    br.select_form(nr=0)
    entest = "%s"  %(sub)
    br.form['post.title']= sub.decode('cp949') + HongboSubject.decode('cp949')
    br.form['post.contents.contentsValue']= con.decode('cp949') + HongboBody.decode('cp949')
    #req = br.click_link(text=u'확인')
    #br.open(req)
    #br.form.click(kind="clickable")
    #for link in br.links():
        #print link
    #br.follow_link(nr=1

    #br.follow_link(text=u"확인")
    #req = br.click(type="submit")
    #br.open(req)   
    br.form.action='http://m.blog.naver.com/PostWrite.nhn'
    br.submit()
    post_count += 1
    print  str(post_count ) +u'개 글올리기 성공!!'  
save.close()
print u'블로그 글올리기 완료!'


推荐答案

您发布的Python代码实际上是不正确的-如果这是您要冻结的实际代码-那么您可能会遇到错误的

The Python code you have posted is actually incorrect - if this is the actual code that you are trying to freeze - then you probably get an error along the lines of

  File "cx_freeze_test.py", line 35
    for line in os.popen("ipconfig /all"):
                                         ^
IndentationError: unindent does not match any outer indentation level

我建议您从一个非常简单的脚本开始,例如

I suggest you start with a very simple script, e.g.

print "hello"

然后您会收到类似以下的错误:

Then you should get an error something like:

  File "C:\_tools\python2.7.0\lib\site-packages\cx_Freeze\freezer.py", line 632, in __init__
    parts = version.split(".")
AttributeError: 'NoneType' object has no attribute 'split'

您可以看到它正在尝试在。上拆分版本字符串。但是,您尚未在setup.py中定义版本。

You can see that it is trying to split the version string on '.'. But you have not defined a version in your setup.py.

所以...再加上

from cx_Freeze import setup, Executable

copyDependentFiles=True
silent = True
includes = ["lxml", "lxml._elementpath", "lxml.etree", "gzip", "encodings.cp949", "encodings.utf_8", "encodings.ascii"]
setup(name='gearfacts',
     version = "1.1",
     options = {
       "build_exe" : {
           "includes": includes,
           },
       },
     executables=[Executable('cx_freeze_test.py')],
 ) 

我最终得到了一个可以在此之后运行的EXE。

I end up with an EXE that can run after this.

这篇关于题python cx_freeze问题ascil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆