Python 2到3

2024-04-24 12:08:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将Python 2转换为Python 3,并出现以下错误:

文件“xenia build”,第48行,main vs\u version=import\u vs\u environment() import\u vs\u环境中的文件“xenia build”,第106行 类型错误:类型str不支持缓冲区API

 # Grab Visual Studio version and execute shell to set up environment.
if sys.platform == 'win32':
vs_version = import_vs_environment()
if vs_version == None:
  print('ERROR: Visual Studio not found!')
  print('Please refer to the building guide:')
  print('  https://github.com/benvanik/xenia/blob/master/docs/building.md')
  sys.exit(1)
  return

def import_vs_environment():
"""Finds the installed Visual Studio version and imports
interesting environment variables into os.environ.

Returns:
A version such as 2015 or None if no VS is found.
"""
version = 0

 candidate_path = subprocess.check_output('third_party/vswhere/vswhere.exe -version "[15,)" -latest -format value -property installationPath', shell=False)
 candidate_path = candidate_path.strip()
 tools_path = ''
if candidate_path:
tools_path = os.path.join  (candidate_path, 'vc\\auxiliary\\build\\vcvarsall.bat')
if os.path.isfile(tools_path) and os.access(tools_path, os.X_OK):
  version = 2017
if version == 0 and 'VS140COMNTOOLS' in os.environ:
version = 2015
tools_path = os.environ['VS140COMNTOOLS']
tools_path = os.path.join(tools_path, '..\\..\\vc\\vcvarsall.bat')
if version == 0:
return None

Tags: andpathimportbuildnoneifenvironmentos
1条回答
网友
1楼 · 发布于 2024-04-24 12:08:25

我认为import_os_environment返回的是字节而不是字符串。在Python3中,subprocess.Popen任何东西都将返回一个字节。你知道吗

尝试使用vs_version = import_os_environment().decode('utf-8')

一个建议是,if not vs_version:比检查if vs_version == None更具脓性。你知道吗

相关问题 更多 >