Windows11使用Cpython?編譯文件報錯?error:?Unable?to?find?vcvarsall.bat?完美解決方法
開發(fā)環(huán)境說明:
- python 3.6.2
- Vs studio 2017 (已經(jīng)安裝C++桌面開發(fā))

我的vcvarsall.bat 路徑為:
"D:\vsstudio\VC\Auxiliary\Build\vcvarsall.bat"
一般在Vs studio 的此安裝路徑下

修改python源代碼
修改文件為 python3.6.2\Lib\distutils\_msvccompiler.py 注意 前面存在下劃線:
我的文件路徑為:
"D:\core_package\python3.6.2\Lib\distutils\_msvccompiler.py"

接下來 使用記事本打開:
- 將_find_vcvarsall 函數(shù)修改:
- 源代碼:
def _find_vcvarsall(plat_spec):
try:
key = winreg.OpenKeyEx(
winreg.HKEY_LOCAL_MACHINE,
r"Software\Microsoft\VisualStudio\SxS\VC7",
access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
)
except OSError:
log.debug("Visual C++ is not registered")
return None, None
with key:
best_version = 0
best_dir = None
for i in count():
try:
v, vc_dir, vt = winreg.EnumValue(key, i)
except OSError:
break
if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
try:
version = int(float(v))
except (ValueError, TypeError):
continue
if version >= 14 and version > best_version:
best_version, best_dir = version, vc_dir
if not best_version:
log.debug("No suitable Visual C++ version found")
return None, None
vcvarsall = os.path.join(best_dir, "vcvarsall.bat")
if not os.path.isfile(vcvarsall):
log.debug("%s cannot be found", vcvarsall)
return None, None
vcruntime = None
vcruntime_spec = _VCVARS_PLAT_TO_VCRUNTIME_REDIST.get(plat_spec)
if vcruntime_spec:
vcruntime = os.path.join(best_dir,
vcruntime_spec.format(best_version))
if not os.path.isfile(vcruntime):
log.debug("%s cannot be found", vcruntime)
vcruntime = None
return vcvarsall, vcruntime修改為:
def _find_vcvarsall(plat_spec):
best_dir = r"D:\vsstudio\VC\Auxiliary\Build"
best_version = 17
vcruntime = None
vcruntime_spec = _VCVARS_PLAT_TO_VCRUNTIME_REDIST.get(plat_spec)
if vcruntime_spec:
vcruntime = os.path.join(best_dir,
vcruntime_spec.format(best_version))
if not os.path.isfile(vcruntime):
log.debug("%s cannot be found", vcruntime)
vcruntime = None
print(vcruntime)
return r"D:\vsstudio\VC\Auxiliary\Build\vcvarsall.bat", vcruntime要修改的 如下圖所示:

如果跟我配置一樣的話 到指定目錄終端下
就可以輸入
python setup.py build_ext --inplace
完成 PYTHON 到 c 的文件編譯啦
成功截圖 如下所示:

注意 編譯完成后要使用時 需要將 .pyx文件 .c文件 .py文件全部刪除 只保留 pyd文件
在其他文件調(diào)用時 不用擔心報錯 可以正常運行

輸出結(jié)果如下所示

到此這篇關(guān)于Windows11使用Cpython 編譯文件報錯 error: Unable to find vcvarsall.bat 完美解決方法的文章就介紹到這了,更多相關(guān)Cpython 編譯文件報錯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python Selenium Cookie 繞過驗證碼實現(xiàn)登錄示例代碼
這篇文章主要介紹了Python Selenium Cookie 繞過驗證碼實現(xiàn)登錄示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-04-04
flask+pymysql實現(xiàn)Web端操作數(shù)據(jù)庫的項目實踐
本文主要介紹了flask+pymysql實現(xiàn)Web端操作數(shù)據(jù)庫的項目實踐,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-06-06
一篇文章弄懂Python中所有數(shù)組數(shù)據(jù)類型
這篇文章主要給大家介紹了關(guān)于Python中所有數(shù)組數(shù)據(jù)類型的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Python具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-06-06
python+selenium實現(xiàn)163郵箱自動登陸的方法
本篇文章主要介紹了python+selenium實現(xiàn)163郵箱自動登陸的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-12-12

