首页 > 解决方案 > 如何在Win10上正确安装Python、VSCode、flake8

问题描述

对于新手的问题,我深表歉意。我正在尝试正确下载 Python 3.7 安装并将其与 VSCode 集成,并使用 flake8 作为 linter。我想为 Blender 开发自定义脚本做好准备。我在Win10 x64上。

  1. 我下载了“python-3.7.8-amd64.exe”安装包,安装好了。
  2. 我确保选中了将 python 添加到安装程序中的 PATH 环境变量的复选框。
  3. 我将 VSCode 指向新安装的解释器,然后被提示安装 linter。
  4. 有人推荐了 flake8,所以我在 VSCode 中选择了它并安装了。
  5. 在安装过程中,我收到以下警告:

WARNING: The script pyflakes.exe is installed in 'C:\Users\futur\AppData\Roaming\Python\Python37\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

WARNING: The script pycodestyle.exe is installed in 'C:\Users\futur\AppData\Roaming\Python\Python37\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

WARNING: The script flake8.exe is installed in 'C:\Users\futur\AppData\Roaming\Python\Python37\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

Successfully installed flake8-3.8.3 importlib-metadata-1.7.0 mccabe-0.6.1 pycodestyle-2.6.0 pyflakes-2.2.0 zipp-3.1.0

我检查了我的环境变量,结果如下:

路径变量

我不明白为什么我在 %APPDATA% 中有两个 Python 目录。有:

C:\Users\futur\AppData\Local\Programs\Python\Python37\Scripts

也:

C:\Users\futur\AppData\Roaming\Python\Python37\Scripts

flake8 安装在 Roaming 文件夹中,而我的主要 Python 安装在

C:\Users\futur\AppData\Local\Programs\Python\Python37

总而言之,这些是我的问题:

  1. flake8 是否安装在错误的目录中?
  2. 我应该添加C:\Users\futur\AppData\Roaming\Python\Python37\Scripts到我的 USER PATH 环境变量还是我的 SYSTEM PATH 环境变量?
  3. 为什么 %appdata% 中有两个 Python 目录?(漫游和本地)

任何关于如何正确设置一切的指导都将是一个巨大的帮助,非常感谢。

编辑 1

非常感谢所有的答案。我想强调一下,我更愿意在不安装 Anaconda 的情况下解决这个问题。

编辑 2

我在这里取得了一些进展。我没有通过 VSCode 安装 flake8,而是跑了python -m pip install flake8,现在一切似乎都很好。

标签: pythonpython-3.xwindowsvisual-studio-codeflake8

解决方案


根据你的描述,我成功安装了 flake8。

我觉得你flake8的安装路径有问题。

其默认路径不会处于漫游状态。默认路径将只有:C:\Users\futur\AppData\Local\Programs\Python\Python37\Scripts 和 C:\Users\futur\AppData\Local\Programs\Python\Python37;</p>

默认为本地,通常存放可执行程序等大容量文件;

建议您可以重新安装python并检查pip的版本和位置(使用“pip --version”)。


推荐阅读