UnicodeEncodeError: 'mbcs' 编解码器无法对位置 0--1 的字符进行编码:运行 PyInstaller 编译的脚本时字符无效 [英] UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character upon running a PyInstaller-compiled script

查看:73
本文介绍了UnicodeEncodeError: 'mbcs' 编解码器无法对位置 0--1 的字符进行编码:运行 PyInstaller 编译的脚本时字符无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了一个我一直在开发的程序,并且一直想将它编译为一个单独的 .exe 文件以进行分发.我决定使用 pyinstaller 3,因为它以前对我有用,但是在成功编译我的文件后,我在运行程序时收到以下消息.

I've just finished a program I've been working on and have been wanting to compile it to a single .exe file for distribution. I decided to use pyinstaller 3 as it has worked for me before however upon successfully compiling my file I get the following message upon running the program.

C:\Users\Luke\Documents\program\dist>viewbot.exe
_ctypes
C:\Users\Luke\AppData\Local\Temp\_MEI59042\_ctypes.pyd
_tkinter
C:\Users\Luke\AppData\Local\Temp\_MEI59042\_tkinter.pyd
Traceback (most recent call last):
  File "<string>", line 7, in <module>
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "C:\Users\Luke\Documents\program\PyInstaller\loader\pyi_importers.py", line 302, in load_module
  File "C:\Python33\lib\tkinter\__init__.py", line 40, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "C:\Users\Luke\Documents\program\PyInstaller\loader\pyi_importers.py", line 474, in load_module
UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: invalid character

如果有帮助,这是我程序的最小代码示例:

If it helps, this is a minimal code example of my program:

import os
import subprocess
from subprocess import call
import time
import tkinter
from tkinter import filedialog
call("color a", shell=True)
root = tkinter.Tk()
root.withdraw()
print ("Please locate your firefox browser)")
path = filedialog.askopenfilename(parent=root,title="Please locate your firefox browser")
path = path + " {0}"
FNULL = open(os.devnull, 'w')
viewed = 0
url = "http://google.com"
refresh = 15
views = 5
call("cls", shell=True)
for i in range(views):
    proc = subprocess.Popen(path.format(url))
    time.sleep(refresh)
    viewed = viewed + 1
    print ("Viewed", viewed, "time")
    proc.terminate()
    call("cls", shell=True)
print ("Viewing finished in", refresh * views, "seconds")
time.sleep(5)

不太确定在这里做什么,因此非常感谢任何帮助:)

Not quite sure what to do here so any help would be much appreciated :)

推荐答案

我有同样的错误信息.我通过在包含要打开的文件路径的字符串中将 \ 替换为 \\ 来修复它.

I had the same error message. I fixed it by replacing \ by \\ in the string containing the path of the file to open.

这篇关于UnicodeEncodeError: 'mbcs' 编解码器无法对位置 0--1 的字符进行编码:运行 PyInstaller 编译的脚本时字符无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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