简体   繁体   English

如何在代码中停止 autopep8 未安装消息

[英]How to stop autopep8 not installed messages in Code

I'm a new Python programmer using the Mac version of VS Code 1.45.1 to create a Django project.我是一个新的 Python 程序员,使用 Mac 版本的 VS Code 1.45.1 创建一个 Django 项目。 I have the Python and Django extensions installed.我安装了 Python 和 Django 扩展。 Every time I save a Django file, Code pops up this window:每次我保存一个Django的文件,代码弹出这个window:

Formatter autopep8 is not installed.  Install?
Source: Python (Extension)  [Yes] [Use black] [Use yapf]

I keep clicking the "Yes" button to install the autopep8 extension but this message keeps popping up nevertheless.我一直单击“是”按钮来安装 autopep8 扩展,但此消息仍然不断弹出。 Is there some trick to configuring VS Code so that this extension will be installed permanently and I stop getting this error?配置 VS Code 是否有一些技巧,以便永久安装此扩展并且我不再收到此错误?

You will receive this prompt if您将收到此提示,如果

  1. You have "formatOnSave" turned on as a setting您已将"formatOnSave"作为设置打开
  2. You selected autopep8 as your formatter您选择 autopep8 作为格式化程序
  3. The Python extension can't find autopep8 Python 扩展找不到 autopep8

So the options are:所以选项是:

  1. Turn off formatting on save保存时关闭格式化
  2. Make sure you successfully installed autopep8 into your environment or you specified the path to autopep8 in your settings确保您已成功将 autopep8 安装到您的环境中,或者您在设置中指定了 autopep8 的路径

My guess is there's an installation failure because you are using a globally installed interpreter and you're not allowed to install where pip wants to put autopep8.我的猜测是安装失败,因为您使用的是全局安装的解释器,并且不允许安装 pip 想要放置 autopep8 的位置。

pip install pep8   
pip install --upgrade autopep8

or或者

"python.formatting.provider": "autopep8"

windows 10: on vscode terminal: windows 10:在 vscode 终端上:

  1. pip install autopep8 pip 安装 autopep8
  2. where autopep8在哪里 autopep8 在此处输入图像描述
  3. vscode -> Settings -> python -> Autopep8 Path: paste step2 vscode -> 设置 -> python -> Autopep8 路径:粘贴step2 在此处输入图像描述

I have also encountered this problem in my computer with Ubuntu 18.04.我在我的电脑上也遇到了这个问题,Ubuntu 18.04。 It turns out that the python extension need some settings.事实证明,python 扩展需要一些设置。 My solution is:我的解决方案是:

  1. Go to Python extension's extension setting. Go 到 Python 扩展的扩展设置。
  2. Find Python>Formatting:Autopep8 Path term查找 Python>Formatting:Autopep8 路径项
  3. Add the full path of the autopep8 that you have installed.添加已安装的 autopep8 的完整路径。

Adding this in for anyone who has this issue running WSL on Windows .为在 Windows 上运行 WSL 时遇到此问题的任何人添加此内容。 You need to either need to be connected to Remote WSL in order to access pep8 in your WSL Python installation or install Python and pep8 on Windows since VS Code will be looking on Windows. You need to either need to be connected to Remote WSL in order to access pep8 in your WSL Python installation or install Python and pep8 on Windows since VS Code will be looking on Windows. No matter how magnificently installed autopep8 may be in WSL, VS Code won't find it.无论在 WSL 中安装autopep8多么出色,VS Code 都找不到它。

So my full solution was:所以我的完整解决方案是:

  1. If you don't have Python installed in Windows, do that (dare I suggest you can even get it in the Microsoft Store!)如果您没有在 Windows 中安装 Python,请执行此操作(我敢建议您甚至可以在 Microsoft Store 中获得它!)
  2. Install autopep8 in your Windows Python instance.在 Windows Python 实例中安装autopep8 eg, from Command Prompt:例如,来自命令提示符:
     python3 -m pip install autopep8
  3. Follow the instructions in any of the other responses if you're still having issues.如果您仍有问题,请按照任何其他回复中的说明进行操作。

The easiest way to work with autopep8 in VSCode to follow the steps:在 VSCode 中使用 autopep8 的最简单方法是遵循以下步骤:

  1. install autopep8 via pip install autopep8 into the desired virtual env通过pip install autopep8将 autopep8 安装到所需的虚拟环境中
  2. Open VSCode and press ctrl +, which will open the settings打开 VSCode 并按ctrl +,这将打开设置
  3. Search for formatter搜索formatter
  4. Select Python-autopep8 in Editor: Default Formatter Select 编辑器中Python-autopep8 Editor: Default Formatter程序
  5. One can also tick the Editor: Format On Save if he/she wishes to如果他/她愿意,也可以勾选Editor: Format On Save
  6. Most importantly, open any.py file in that directory via VSCode and check at the bottom right of the of the VSCode window. Make sure that it is showing the venv name where the autopep8 has been installed and configured.最重要的是,通过 VSCode 打开该目录中的 any.py 文件并检查 VSCode window 的右下角。确保它显示已安装和配置 autopep8 的 venv 名称。 在此处输入图像描述

Install autopep from your terminal by running the following command通过运行以下命令从终端安装 autopep

    python -m pip install autopep8

That should solve the error 2 in vscode of no such file or directory error那应该可以解决vscode中没有此类文件或目录错误的错误2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我已经安装了 python 扩展,如何将 VS Code 中的路径更改为扩展,以及 autopep8 的正确路径是什么? - How can I change the path in VS Code to the extension and what is the correct path to autopep8 if I already installed the python extension? Visual Studio Code 和 Autopep8 格式化程序 - Visual Studio Code and Autopep8 Formatter Python autopep8 和 VS Code 集成 - Python autopep8 and VS Code integration VS 代码,Python ext,autopep8 未格式化 - VS Code, Python ext, autopep8 not formatting 如何在 ipython notebook 中使用 autoPep8 扩展 - how to use autoPep8 extension with ipython notebook 带有 PyLint 和 autoPep8 的 Visual Studio 代码:如何避免 PyLint 抱怨我的行长? - Visual Studio code with PyLint and autoPep8: How can I avoid PyLint to complain about my line length? 如何在 Visual Studio Code 中保存 Python 文件后*自动*运行 *BOTH* black 和 autopep8 *自动*? - How to run *BOTH* black and autopep8 *AUTOMATICALLY* upon saving a Python file in Visual Studio Code? 尝试在 VSCode、Windows WSL2 上全局安装 autopep8 - Trying to get autopep8 installed globally on VSCode, Windows WSL2 在 VS Code 中,我安装了 autopep8,路径没问题,我可以在终端中使用它,但无法在命令面板中找到它 - In VS Code, I have autopep8 installed, the path is ok, I can use it in the terminal but can't locate it in the Command Palette 在pydev中使用AutoPep8 - Using AutoPep8 in pydev
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM