最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

VS Code no longer can find Python path used by pyenv - Stack Overflow

programmeradmin8浏览0评论

I have been using VS Code for Python development on Windows 10 for years. For some time, I have been using pyenv-win to manage installed Python versions in Windows. Once I've configured the version of Python I want to use, I create a virtual environment by entering the following in a PowerShell terminal:

python -m venv .venv

I then follow the standard process of activating the virtual environment and installing packages:

(venv) python -m pip install <stuff>

In VS Code I have the Microsoft Python extension installed and enabled, along with the Microsoft extensions Python Debugger and Pylance. When I launch VS Code, and open a Python file, I'm prompted to select an interpreter. I navigate to the location of the interpreter in my virtual environment. I have the following configured in my launch.json file for the project:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: /?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Current File",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": false
        }
    ]
}

This overall configuration has worked for a couple of years.

Starting a few months ago, when attempting to debug a Python file in VS Code, I get the following error in the "Call Stack" panel of the "Run and Debug" pane:

[WinError 3] The system cannot find the path specified: 'C:\\Users\\<username>\\AppData\\Roaming\\Python\\Python310\\site-packages'

I gather that at some point I must've had pyenv-win installing Python interpreters in %AppData% or something, rather than in ~\.pyenv\pyenv-win\versions. Or maybe not that, I'm kind of at a loss. For some reason, somewhere along the expansion of all the path aliases, %AppData%\Roaming\ is being inserted into the effective interpreter path. This is specified nowhere in my $PATH or $PYTHONPATH or any of the interpreter settings in VS Code (that I've found).

Another quirky thing? I have no issues running the very same Python script in a PowerShell terminal, including the terminal integrated into VS Code. This leads me to believe the issue is some stray setting that is affecting the debugpy extension. However, the command entered into the terminal when starting debugging in VS Code (I just press F5) includes the explicit path to the Python interpreter in my virtual environment. Moreover, manually typing that path in the same terminal window/session just works and throws no errors, just like typing python ... does. Running

gcm python | Format-List *

in the activated virtual environment returns the correct path to the pyenv-win shims directory.

I don't recall if I installed any updates to the VS Code Python-related extensions, nor what changed on my system a few months ago that precipitated the errors. I have made no gross, global changes to any of my workflow, that I can recall: same computer, same install of Windows 10, same install of pyenv-win (I think). It might be that I used to have system Python installed in %AppData%\Roaming\ but removed it, and there's something in the pyenv-win configuration/setup that needs to be updated. However, I've done some ripgrep searches in (at least some of) the relevant directories and not found anything obviously incriminating.

I appreciate any tips or help.

Cheerio!

[EDIT TO ADD]: I just attempted to execute a script using the "Run Python File" command (under the play arrow) and there were no path errors. Trying to run with the debugger is where the error arises.

发布评论

评论列表(0)

  1. 暂无评论