简体   繁体   English

VS Code - 使用 Conda/Pip 安装 autopep8 时出错

[英]VS Code - Error in installing autopep8 with Conda/Pip

In my VS Code, I got the Python extension running, Python 3.6.1 and Anaconda3 installed.在我的 VS Code 中,我运行了 Python 扩展,安装了 Python 3.6.1 和 Anaconda3。 When I copy and paste some code, VS Code asked me to install autopep8.当我复制和粘贴一些代码时,VS Code 要求我安装 autopep8。 When I press "Yes", it shows a box as当我按“是”时,它显示一个框跟随 . .

First I chose "Install using Conda".首先,我选择了“使用 Conda 安装”。 Next, the following error message pops out and it failed to properly install autopep8:接下来,弹出以下错误消息,并且无法正确安装 autopep8:

PS D:\Python> conda activate base

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.

To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - cmd.exe
  - fish
  - tcsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.


PS D:\Python> & conda install --name base autopep8
Collecting package metadata (current_repodata.json): failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/win-64/current_repodata.json>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.

If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.

'https://repo.anaconda.com/pkgs/main/win-64'

I don't understand what the message means.我不明白这个消息是什么意思。 Can anyone help me?谁能帮我?

Note: Here's all the paths I've included in the PATH:注意:这是我在 PATH 中包含的所有路径: PATH 中包含的路径

Ok I figured the solution to this problem.好的,我想出了这个问题的解决方案。 The root cause is that my Powershell is not configured to allow scripts from running in my system.根本原因是我的 Powershell 未配置为允许脚本在我的系统中运行。 Here are the steps if anyone has this problem too:如果有人也有这个问题,这里是步骤:

  1. Launch Powershell as administrator以管理员身份启动 Powershell
  2. Set-ExecutionPolicy -ExecutionPolicy Unrestricted and pick Y Set-ExecutionPolicy -ExecutionPolicy Unrestricted并选择Y
  3. Within Powershell, type conda init powershell and run在 Powershell 中,输入conda init powershell并运行
  4. Re-open VS Code.重新打开 VS Code。 Then copy and paste some Python code in the .py file然后将一些 Python 代码复制并粘贴到 .py 文件中
  5. At the bottom right corner, VS Code will ask whether to install autopep8.在右下角,VS Code 会询问是否安装 autopep8。 Choose Yes.选择是。
  6. VS Code will then automatically run some Powershell commands.然后 VS Code 会自动运行一些 Powershell 命令。 This should work now这应该现在工作

Your installation under conda failed because you have not set up your shell to use conda.您在 conda 下的安装失败,因为您尚未将 shell 设置为使用 conda。 The instructions are a little down in the error message on how to set this up:有关如何设置的错误消息中的说明略有下降:

To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - cmd.exe
  - fish
  - tcsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

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

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