(20201024Solved)vsCode debug出现no such file or directory:‘/home/user/.local/lib‘

  • Problem Description

    python file.pyIt can run normally, and debugthere will be problems like the question:

    no such file or directory: '/home/user/.local/lib'
    

    Looking at the running path, it should be pythona ospath check.

  • Thinking combing

    • Keyword

    debugBefore the actual content of a file, vscode will check first, the function that went wrong is:

    home/user/anaconda3/lib/python3.8/posixpath.pyin

    # This will always return false on systems where os.lstat doesn't exist
    def islink(path):
            # Test whether a path is a symbolic link
            try:
                st = os.lstat(path)
            except (OSError, ValueError, AttributeError):
            return False
        return stat.S_ISLNK(st.st_mode)
    

    OK, here are a few keywords:[posixpath.py, os.lstat, islink, stat, path, symbolic]

    First look at what is inside the two variables of input pathand output stat:

    • pathIs home/user/.local/libthis problem of path
    • statYes<module 'stat' from 'home/user/anaconda3/lib/python3.8/stat.py'>

    Then the question is turned into research keywords (stat.py, posixpath.py). These two modules are the problem. It can be seen that the problem statis import statin the posixpath.pymiddle, so the breakthrough point of the problem is this posixpath.py.

    " Understanding in Python posixpath.py " we talked about, and posixpath.pythat is POSIX system under os.paththe common moduleof Source File .

    • Soft link

    islink()The function is suitable for judging whether the path is a symbolic link , " Understanding what is a symbolic link in Python ".

    I have sorted out a lot before. The core of the problem is that the os.path module uses a islink()function to determine path=/home/user/.local/libwhether it is a soft connection error because there is no /home/user/.local/libsuch path.

    • vscode

    There is indeed no check, how did this path come from. Then find a breakthrough from the principle of vscode debug .

    From Python debug configurations in Visual Studio Code , VS Code debug will use the configuration in *.vscode/launch.json , which path=/home/user/.local/libis mostly specified by launch.json*, delete it first, and re- debugsolve the problem.

  • solution

    Delete the *.vscode/launch.json* file, restart F5 dubug, and solve the problem.

    For how to set launch.json, path=/home/user/.local/libplease refer to Python debug configurations in Visual Studio Code , which will be explained in detail after it is empty.

  • Reference

  1. Python debug configurations in Visual Studio Code

Guess you like

Origin blog.csdn.net/The_Time_Runner/article/details/109277059