简体   繁体   English

尝试在 Vim 中使用 Python 格式化 JSON 文件会引发错误

[英]Trying to format JSON file with Python in Vim throws error

I have a JSON file that I opened with Vim and want to format to make it a bit more readable.我有一个用 Vim 打开的 JSON 文件,想对其进行格式化以使其更具可读性。

I followed the advice of many Stack Overflow answers and other blog posts, and ran the command:我遵循了许多 Stack Overflow 答案和其他博客文章的建议,并运行了以下命令:

:%!python -m json.tool

After running this command the Vim prompts me to press Enter or enter a command, and when I press Enter I get the following message highlighted in red:运行此命令后,Vim 提示我按Enter或输入命令,当我按Enter 时,我收到以下以红色突出显示的消息:

Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640

The link that's shown leads me to Python 3.8 in Microsoft Store which is a little strange to me.显示的链接将我带到了 Microsoft Store 中的 Python 3.8,这对我来说有点奇怪。

Why is this error occurring and what can I do to simply format my JSON file?为什么会发生此错误,我该怎么做才能简单地格式化我的 JSON 文件? Thanks.谢谢。

Do you have python installed on your computer?你的电脑上安装了python吗? This command:这个命令:

:%!python -m json.tool

uses python from the operative systems and passes the info from your JSON as a parameter.使用操作系统中的 python 并将您的 JSON 中的信息作为参数传递。 Run the following from the terminal, it should print the current version of python:从终端运行以下命令,它应该打印 python 的当前版本:

python --version

Assuming you have python installed, and since the vim code is correct, are you running vim on a simulator ie VS Code?假设你已经安装了 python,并且由于 vim 代码是正确的,你是否在模拟器上运行 vim,即 VS Code? the issue might be related to the environment variables.该问题可能与环境变量有关。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM