简体   繁体   English

尝试为 Python 3.8 打开空闲时出现 UnicodeDecodeError

[英]UnicodeDecodeError when trying to open Idle for Python 3.8

I tried launching idle on the command prompt by using python -i -m idlelib This the error that occurred:我尝试使用python -i -m idlelib在命令提示符下启动空闲 这是发生的错误:

Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized  
Traceback (most recent call last):  
  File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\site.py", line 580, in <module>
    main()  
  File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\site.py", line 567, in main
    known_paths = addsitepackages(known_paths)  
  File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\site.py", line 350, in addsitepackages      
    addsitedir(sitedir, known_paths)  
  File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\site.py", line 208, in addsitedir  
    addpackage(sitedir, name, known_paths)  
  File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\site.py", line 164, in addpackage
    for n, line in enumerate(f):  
  File "C:\Users\_\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]  
  UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 654: character maps to undefined

Try python -i first and see if you can access the idle on the console.先试试python -i看看能不能在控制台访问空闲。

Once you've verified that, you should then open idle on your pc and try import idlelib .一旦你验证了这一点,你应该在你的电脑上打开 idle 并尝试import idlelib If it doesn't load that means that either you don't have that module or its not in you path (which you can fix by finding its location and running import sys; sys.path.append("path/to/module") ).如果它没有加载,这意味着你没有那个模块或者它不在你的路径中(你可以通过找到它的位置并运行import sys; sys.path.append("path/to/module") )。

My guess would be that you have multiple versions of python on your pc and when you're running python you are not using the version that has this module.我的猜测是您的 PC 上有多个版本的 python 并且当您运行 python 时,您没有使用具有此模块的版本。

A person here seems to have had a similar problem, albeit with a different program where the environmental variables they used caused problems.这里的一个人似乎遇到了类似的问题,尽管他们使用的环境变量导致问题的程序不同。 I recommend getting a package like conda.我建议购买像 conda 这样的 package。 That'll reduce the likelihood of running into these problems immensely.这将大大降低遇到这些问题的可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM