简体   繁体   中英

Which Python environment is used in VS Code and how do I install extra packages?

I'm using Ubuntu 20.04 with pyenv on my console to choose the Python version.

For the following, see screenshot below.

Within VS Code, I pointed the version (1) to my pyenv version (2). It tells me that astor is not installed (3). It definitely is installed, so my run configuration is using another environment.

在此处输入图片说明

my launch.json :

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

Which environment does VS Code (with pylance) use? How can I make it use the pyenv environment? Is there another option to install the required packages in that environment?

What I've tried

Adding it to the extras in settings:

在此处输入图片说明

Installing it within the console:

在此处输入图片说明

  1. Since we use " pip " to install the module " astor ", the source of pip used determines where the module is installed. We can use " pip --version " or " pip3 --version " to check the source of pip :

    在此处输入图片说明

    Please use the shortcut key Ctrl+Shift+` to open a new VSCode terminal, it will automatically enter the currently selected environment.

  2. Use " pip " to install " astor ": " pip install astor " or " pip3 install astor ".

  3. Check the installation package. Use " pip list ":

    在此处输入图片说明

  4. Result:

    在此处输入图片说明

Other ways to install modules:

On the premise that "Anaconda" has been installed, use conda to install the module in VSCode: " conda install astor ":

在此处输入图片说明

For more use, you can refer to: Environment in VSCode.

Update:

在此处输入图片说明

Please try to reload VSCode or reopen VSCode.

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