简体   繁体   中英

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. When I copy and paste some code, VS Code asked me to install autopep8. When I press "Yes", it shows a box as跟随 .

First I chose "Install using Conda". Next, the following error message pops out and it failed to properly install 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 中包含的路径

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. Here are the steps if anyone has this problem too:

  1. Launch Powershell as administrator
  2. Set-ExecutionPolicy -ExecutionPolicy Unrestricted and pick Y
  3. Within Powershell, type conda init powershell and run
  4. Re-open VS Code. Then copy and paste some Python code in the .py file
  5. At the bottom right corner, VS Code will ask whether to install autopep8. Choose Yes.
  6. VS Code will then automatically run some Powershell commands. This should work now

Your installation under conda failed because you have not set up your shell to use 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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