简体   繁体   English

安装和卸载Python2后出现错误

[英]Error after Installing and Uninstalling Python2

im working with python 3 but needed to install python 2 for some testing. 我正在使用python 3,但需要安装python 2进行一些测试。 After uninstalling python2 if I run my python 3 Code I get the following Error: 卸载python2后,如果运行python 3代码,则会出现以下错误:

Failed to import the site module
Traceback (most recent call last):
  File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\site.py", line 570, in <module>
main()
  File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\site.py", line 557, in main
known_paths = addsitepackages(known_paths)
  File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\site.py", line 349, in addsitepackages
addsitedir(sitedir, known_paths)
  File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\site.py", line 207, in addsitedir
    addpackage(sitedir, name, known_paths) 
 File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\site.py", line 159, in addpackage
f = open(fullname, "r")
  File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\_bootlocale.py", line 12, in getpreferredencoding
if sys.flags.utf8_mode:
AttributeError: 'sys.flags' object has no attribute 'utf8_mode'
Failed to import the site module
Traceback (most recent call last):
  File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\site.py", line 570, in <module>
    main()
  File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\site.py", line 557, in main
known_paths = addsitepackages(known_paths)
  File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\site.py", line 349, in addsitepackages
addsitedir(sitedir, known_paths)
  File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\site.py", line 207, in addsitedir
addpackage(sitedir, name, known_paths)
  File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\site.py", line 159, in addpackage
f = open(fullname, "r")
  File "C:\Users\2325\AppData\Local\Programs\Python\Python37\lib\_bootlocale.py", line 12, in getpreferredencoding
if sys.flags.utf8_mode:
AttributeError: 'sys.flags' object has no attribute 'utf8_mode'

This is my Code: 这是我的代码:

#!/usr/bin/env python3
# encoding: utf-8

import json, argparse, subprocess

argparser = argparse.ArgumentParser(description="Executes every task")
argparser.add_argument('--taskjson', type=str, required=True    help="Required Json with tasks")
args = argparser.parse_args()

with open(args.taskjson) as f:
     data=json.load(f)
     data=data["tasks"]

     locationoffiletoget = [None]*len(data)
     locationoffiletoput = [None]*len(data)
     nameoffiletoget = [None]*len(data)
     nameoffiletoput = [None]*len(data)
     nameofsheettoput = [None]*len(data)
     nameofsheettoget = [None]*len(data)
     putdataunder = [None]*len(data)
     putdatabehind = [None]*len(data)
     rowstoskipatgetfile = [None]*len(data)
     thingsToReplace = [None]*len(data)
     formatget = [None]*len(data)
     formatput = [None]*len(data)
     columnsToFormatToDate = [None]*len(data)


    for i in range(0,len(data)):            
        subprocess.call(["ExecutingScript.py",\                         
                     data[i]["locationoffiletoget"],\
                     data[i]["locationoffiletoput"],\
                     data[i]["nameoffiletoget"],\
                     data[i]["nameoffiletoput"],\
                     data[i]["nameofsheettoput"],\
                     data[i]["nameofsheettoget"],\
                     data[i]["putdataunder"],\
                     data[i]["putdatabehind"],\
                     data[i]["rowstoskipatgetfile"],\
                     data[i]["formatget"],\
                     data[i]["formatput"],\
                     data[i]["columnsToFormatToDate"]], shell=True)

As you can see there is nothing that would make this error appear. 如您所见,没有任何东西会使此错误出现。 If I run a simple hello world program everything works fine. 如果我运行一个简单的hello world程序,则一切正常。

I dont really know why but, there's no attribute named utf8_mode inside sys.flags. 我真的不知道为什么,但是,在sys.flags中没有名为utf8_mode的属性。 If you want to see and compare the encoding, try: 如果要查看和比较编码,请尝试:

if sys.getdefaultencoding() == 'utf-8':
    continue

Or maybe: 或者可能:

if sys.getfilesystemencoding() == 'utf-8':
    continue

I'm not really sure what you are doing with it, since there's no code so this is the limit of what I can do. 我不确定自己在做什么,因为没有代码,所以这是我所能做的限制。

Edit: The error seems to be on the _bootlocale.py file inside the python's lib folder. 编辑:错误似乎在python的lib文件夹内的_bootlocale.py文件上。 I thin that some remnants from python 2.x was left and wasnt overwritten or updated after returning to 3.x 我认为从python 2.x来的一些残余被遗留下来,并且在返回3.x之后并没有被覆盖或更新。

I think uninstalling then deleting the whole python folder, and checking local_variables just in case, before reinstalling python 3.x will fix it, though i'm not sure if it will. 我认为卸载然后删除整个python文件夹,并检查local_variables以防万一,在重新安装python 3.x之前会解决它,尽管我不确定是否会。

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

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