[英]Error after Installing and Uninstalling Python2
我正在使用python 3,但需要安裝python 2進行一些測試。 卸載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'
這是我的代碼:
#!/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)
如您所見,沒有任何東西會使此錯誤出現。 如果我運行一個簡單的hello world程序,則一切正常。
我真的不知道為什么,但是,在sys.flags中沒有名為utf8_mode的屬性。 如果要查看和比較編碼,請嘗試:
if sys.getdefaultencoding() == 'utf-8':
continue
或者可能:
if sys.getfilesystemencoding() == 'utf-8':
continue
我不確定自己在做什么,因為沒有代碼,所以這是我所能做的限制。
編輯:錯誤似乎在python的lib文件夾內的_bootlocale.py文件上。 我認為從python 2.x來的一些殘余被遺留下來,並且在返回3.x之后並沒有被覆蓋或更新。
我認為卸載然后刪除整個python文件夾,並檢查local_variables以防萬一,在重新安裝python 3.x之前會解決它,盡管我不確定是否會。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.