Windows11使用Cpython?編譯文件報(bào)錯(cuò)?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 的文件編譯啦
成功截圖 如下所示:
注意 編譯完成后要使用時(shí) 需要將 .pyx文件 .c文件 .py文件全部刪除 只保留 pyd文件
在其他文件調(diào)用時(shí) 不用擔(dān)心報(bào)錯(cuò) 可以正常運(yùn)行
輸出結(jié)果如下所示
到此這篇關(guān)于Windows11使用Cpython 編譯文件報(bào)錯(cuò) error: Unable to find vcvarsall.bat 完美解決方法的文章就介紹到這了,更多相關(guān)Cpython 編譯文件報(bào)錯(cuò)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python報(bào)錯(cuò)解決之python運(yùn)行bat文件的各種問題處理
- python實(shí)現(xiàn)遠(yuǎn)程運(yùn)行bat文件
- python神經(jīng)網(wǎng)絡(luò)Batch?Normalization底層原理詳解
- python神經(jīng)網(wǎng)絡(luò)之批量學(xué)習(xí)tf.train.batch函數(shù)示例
- python生成器generator:深度學(xué)習(xí)讀取batch圖片的操作
- Python產(chǎn)生batch數(shù)據(jù)的操作
- python非阻塞式后臺(tái)如何運(yùn)行bat腳本
相關(guān)文章
python實(shí)現(xiàn)差分隱私Laplace機(jī)制詳解
今天小編就為大家分享一篇python實(shí)現(xiàn)差分隱私Laplace機(jī)制詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11使用Python圖像處理庫Pillow處理圖像文件的案例分析
本文將通過使用Python圖像處理庫Pillow,幫助大家進(jìn)一步了解Python的基本概念:模塊、對(duì)象、方法和函數(shù)的使用,文中代碼講解的非常詳細(xì),需要的朋友可以參考下2023-07-07pytorch制作自己的LMDB數(shù)據(jù)操作示例
這篇文章主要介紹了pytorch制作自己的LMDB數(shù)據(jù)操作,結(jié)合實(shí)例形式分析了pytorch使用lmdb的相關(guān)操作技巧與使用注意事項(xiàng),需要的朋友可以參考下2019-12-12YOLOv5車牌識(shí)別實(shí)戰(zhàn)教程(四)模型優(yōu)化與部署
這篇文章主要介紹了YOLOv5車牌識(shí)別實(shí)戰(zhàn)教程(四)模型優(yōu)化與部署,在這個(gè)教程中,我們將一步步教你如何使用YOLOv5進(jìn)行車牌識(shí)別,幫助你快速掌握YOLOv5車牌識(shí)別技能,需要的朋友可以參考下2023-04-04通過Python pyecharts輸出保存圖片代碼實(shí)例
這篇文章主要介紹了通過Python pyecharts輸出保存圖片代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11Django項(xiàng)目中用JS實(shí)現(xiàn)加載子頁面并傳值的方法
今天小編就為大家分享一篇Django項(xiàng)目中用JS實(shí)現(xiàn)加載子頁面并傳值的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-05-05通過Python的speech_recognition庫將音頻文件轉(zhuǎn)為文字
recognize_google()?是Google提供的一種語音識(shí)別API,可以識(shí)別音頻文件或麥克風(fēng)錄制的語音,并將其轉(zhuǎn)換為文本,這篇文章主要介紹了通過Python的speech_recognition庫將音頻文件轉(zhuǎn)為文字,需要的朋友可以參考下2023-05-05