简体   繁体   中英

How do I make Poetry site-packages searchable on VSCode?

VSCode supports many virtual environments as default and those environments' files are searchable. However, I'm using Poetry and its libraries don't seem to come up on the search.

I manually set my Python interpreter by changing .vscode/settings.json in my project directory. (Because command palette's Python: Select interpreter didn't work either.

{
    "python.pythonPath": "~\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\finance-essentials-37-64-58e2e1Bc-py3.7\\Scripts"
}

I want to make files in ~\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\finance-essentials-37-64-58e2e1Bc-py3.7\\Lib\\site-packages searchable on my command pelette & code context so that I can look up library sources easily.

How do I do this?

I like this question, actually. Being able to search and look through packages easily makes one more productive.

There's a good answer here .

VS Code multi-root workspaces explained in-depthhere , as fellow snarky Canadian @BrettCannon mentioned .

In VS Code, you just need to click on File -> Add Folder to Workspace... and locate your Poetry virtual environment, or wherever your site-packages folder is, which contains your externally-installed libraries/packages.

Or... to do the exact-same-thing as above the hard way... Just create a JSON-based workspace.code-workspace file in your .vscode directory, alongside your launch.json and settings.json files. This will load your multi-root workspace automatically when you reload VS Code. Then paste in the following contents, changing the second path as required for your own site-packages folder:

{
    "folders": [
        {
            "path": ".."
        },
        {
            "path": "../../usr/local/lib/python3.9/site-packages"
        }
    ],
    "settings": {}
}

You could use a multi-root workspace that includes your code and the site-packages directory.

Although I would ask why you feel the need to have installed 3rd-party code searchable in that way? General code navigation from within the Python extension should help you discover details of the code you're using and documentation should be the primary way to learn about the code you're using.

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