使用cx freeze和UnicodeDecodeError

时间:2015-10-29 12:59:51

标签: python sqlite unicode cx-freeze

我是新来的,我在尝试使用cx-freeze冻结脚本时遇到的错误有一个小问题。

所以我在这里和那里搜索了一些内容,找到了这两个页面:herehere。第一个对我没有帮助,因为我的代码与pygame或其他任何东西都无关。第二个更接近我的问题,但似乎他的脚本被冻结后得到错误,而我试图冻结它。 另外,我不太了解给他的答案(关于"小脚本"他必须跑)。

所以我使用Python 2.7.8和Anaconda在Windows 64bits上运行所有内容。 我有一些代码(运行良好):

import random as rd
import sqlite3

base=sqlite3.connect("Test_anglais.sqlite")  

def test():
    n=int(input("How many words would you like to review ? \n"))
    for i in range(n):
        rand=rd.randint(1,130)
        recherche=base.execute("SELECT Français FROM vocabulaire WHERE rowid=?", (rand,))
        L=recherche.fetchall()
        question=L[0][0]
        reponse=raw_input("""Please give me the english translation of "%s" : \n""" %question)
        reponse=unicode(reponse)
        recherche=base.execute("SELECT Anglais FROM vocabulaire WHERE rowid=?", (rand,))
        L=recherche.fetchall()
        answer=L[0][0]
        if answer==reponse:
            print(u"Well done !")
            print('\n')
        else :
            print("""You'll need to study a little bit more... The right answer was "%s".""" %answer)
            print("\n")

test()

这里没什么复杂的,我只是从数据库中添加随机的法语单词(在utf-8中),用英语请求翻译,看看它是否正确。

然后我有一个steup.py文件来冻结它:

from cx_Freeze import setup, Executable

setup(
    name = "Vocab Test",
    version = "0.1",
    description = "This program will help you review your english vocab",
    executables = [Executable("teste_ton_vocab.py")],
)

但是,当我问

  

python.exe setup.py build

我得到了一个非常长的错误描述,就像这样:

running build
running build_exe
creating directory build\exe.win-amd64-2.7
copying C:\Anaconda\lib\site-packages\cx_Freeze\bases\Console.exe -> build\exe.win-amd64-2.7\teste_ton_vocab.exe
copying C:\Anaconda\python27.dll -> build\exe.win-amd64-2.7\python27.dll
Traceback (most recent call last):
  File "setup.py", line 17, in <module>
    executables = [Executable("teste_ton_vocab.py")],
  File "C:\Anaconda\lib\site-packages\cx_Freeze\dist.py", line 362, in setup
    distutils.core.setup(**attrs)
  File "C:\Anaconda\lib\distutils\core.py", line 151, in setup
    dist.run_commands()
  File "C:\Anaconda\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Anaconda\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Anaconda\lib\distutils\command\build.py", line 127, in run
    self.run_command(cmd_name)
  File "C:\Anaconda\lib\distutils\cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "C:\Anaconda\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Anaconda\lib\site-packages\cx_Freeze\dist.py", line 232, in run
    freezer.Freeze()
  File "C:\Anaconda\lib\site-packages\cx_Freeze\freezer.py", line 621, in Freeze
    self._FreezeExecutable(executable)
  File "C:\Anaconda\lib\site-packages\cx_Freeze\freezer.py", line 211, in _FreezeExecutable
    self._AddVersionResource(exe.targetName)
  File "C:\Anaconda\lib\site-packages\cx_Freeze\freezer.py", line 150, in _AddVersionResource
    stamp(fileName, versionInfo)
  File "C:\Anaconda\lib\site-packages\win32\lib\win32verstamp.py", line 157, in stamp
    vs = VS_VERSION_INFO(vmaj, vmin, vsub, vbuild, sdata, vdata, is_debug, is_dll)
  File "C:\Anaconda\lib\site-packages\win32\lib\win32verstamp.py", line 105, in VS_VERSION_INFO
    result = pad32(result) + StringFileInfo(sdata) + VarFileInfo(vdata)
  File "C:\Anaconda\lib\site-packages\win32\lib\win32verstamp.py", line 83, in StringFileInfo
    result = pad32(result) + StringTable('040904E4', data)
  File "C:\Anaconda\lib\site-packages\win32\lib\win32verstamp.py", line 75, in StringTable
    result = result + String(k, v)
  File "C:\Anaconda\lib\site-packages\win32\lib\win32verstamp.py", line 64, in String
    value = nullterm(value)
  File "C:\Anaconda\lib\site-packages\win32\lib\win32verstamp.py", line 50, in nullterm
    return (unicode(s) + u'\0').encode('unicode-internal')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 32: ordinal not in range(128)

所以我在这里,我真的不知道该做什么或它可能来自哪里。 得到错误的一行;第32行,如果我把它弄好了这个:

  

打印(&#34;&#34;&#34;你需要多学习一点......正确的答案是&#34;%s&#34;。&#34; &#34;&#34;%回答)

所以我猜它与&#34;答案&#34;有关。我来自数据库。 (它是一个unicode链,例如你在公司内部的培训&#39;例如)。

你有什么想法吗?我尽量做到尽可能准确,对于长篇消息和所有人都抱歉...

感谢您的帮助!

麦娘

PS:顺便说一句,我不应该在setup.py文件中的某处添加数据库Test_anglais.sqlite ??

0 个答案:

没有答案