简体   繁体   中英

Error after Installing and Uninstalling Python2

im working with python 3 but needed to install python 2 for some testing. After uninstalling python2 if I run my python 3 Code I get the following Error:

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.

I dont really know why but, there's no attribute named utf8_mode inside sys.flags. 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. I thin that some remnants from python 2.x was left and wasnt overwritten or updated after returning to 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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