溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

VSCode中autopep8無(wú)法運(yùn)行怎么辦

發(fā)布時(shí)間:2021-03-02 13:58:25 來(lái)源:億速云 閱讀:857 作者:小新 欄目:開(kāi)發(fā)技術(shù)

這篇文章給大家分享的是有關(guān)VSCode中autopep8無(wú)法運(yùn)行怎么辦的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。

錯(cuò)誤現(xiàn)象:autopep8無(wú)法運(yùn)行,運(yùn)行后vscode右下角提示

Error: Command failed: autopep8 c:\Users\Administrator\Desktop\Python\第1章 概述\1-10.py usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename] [--ignore-local-config] [-r] [-j n] [-p n] [-a] [--experimental] [--exclude globs] [--list-fixes] [--ignore errors] [--select errors] [--max-line-length n] [--line-range line line] [--hang-closing] [--exit-code] [files [files ...]] autopep8: error: autopep8 only takes one filename as argument unless the "--in-place" or "--diff" args are used

usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename] [--ignore-local-config] [-r] [-j n] [-p n] [-a] [--experimental] [--exclude globs] [--list-fixes] [--ignore errors] [--select errors] [--max-line-length n] [--line-range line line] [--hang-closing] [--exit-code] [files [files ...]] autopep8: error: autopep8 only takes one filename as argument unless the "--in-place" or "--diff" args are used

錯(cuò)誤原因 :

文件路徑中包含有空格!

VSCode中autopep8插件運(yùn)行無(wú)效問(wèn)題解決(插件運(yùn)行,但不格式化代碼)

問(wèn)題現(xiàn)象:運(yùn)行autopep8之后,提示插件正常運(yùn)行,但是代碼沒(méi)有任何變化。

問(wèn)題解決過(guò)程:

1.首先在命令行中使用autopep8 文件路徑.py進(jìn)行測(cè)試,運(yùn)行后命令行中顯示所有代碼,但未格式化文檔。

2.根據(jù)運(yùn)行autopep8的命令幫助以及網(wǎng)絡(luò)查詢(xún)可知,autopep8運(yùn)行時(shí)應(yīng)加上--in-place --aggressive參數(shù)

命令格式即為 autopep8 --in-place --aggressive 文件路徑名.py

命令行中運(yùn)行autopep8問(wèn)題解決!

3.如何在VSCode中為autopep8增加參數(shù)?

嘗試在preference>setting中設(shè)置autopep8Args,但是無(wú)效!

搜索文件找到C:\Users\Administrator\.vscode\extensions\himanoa.python-autopep8-1.0.2目錄,即擴(kuò)展安裝目錄。

打開(kāi)extension.js文件。

找到

 exec('autopep8 ' + filename, function(error, stdout, stderr){

將其修改為

 exec('autopep8 --in-place --aggressive ' + filename, function(error, stdout, stderr){

重啟VSCode,問(wèn)題解決!

感謝各位的閱讀!關(guān)于“VSCode中autopep8無(wú)法運(yùn)行怎么辦”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI