I installed a library inside a virtual environment using venv in Visual Studio Code, then imported it into a Python file. However, when I run the file, I get a ModuleNotFoundError.
Attempted steps and checks:
- I do not have multiple versions of Python installed.
- I activated the venv before installing the module and before running the file.
- VS Code says that it is using the Python executable in \venv\scripts.
- The module is in fact in
venv\Lib\site-packages. - I am running the latest version of pip both within and without the venv.
- I restarted VS Code.
Oddities:
- Running the file from the built-in terminal works rather than raising an error.
-
which pythonin Bash returns/c/Users/Lyndon/Documents/VS Code/seatmap_parser/\Users\Lyndon\Documents\VS Code\seatmap_parser\venv/Scripts/pythonwhen it should presumably returnC:\Users\Lyndon\Documents\VS Code\seatmap_parser\venv\Scripts\python. - Adding the setting
"python.pythonPath": "${workspaceRoot}/venv/Scripts/python"to workspacesettings.jsonraises this error:The Python path in your debug configuration is invalid. - If I deactivate the venv, install the module globally, and reactivate the venv, the file now works, leading me to think that perhaps somehow the wrong Python executable is running anyway.
I stand ready to check for any missed details upon request. Why isn't it working?
https://stackoverflow.com/questions/67029492/modulenotfounderror-when-importing-installed-module-in-venv April 10, 2021 at 07:38AM
没有评论:
发表评论