Python Pylint Import Error #46885
-
I have an issue where the VSCode in Codespaces is not correctly identifying imports that are installed. The error is a Pylint error stating that a any of my imports cannot be imported, but this is inaccurate as the scripts run perfectly fine. If I hover over the error there will be a description of the library/module that is accurate to indicate it was correctly imported, but a secondary error from Pylint saying it failed. I have installed the VSCode Extensions and even tried with in both current and pre-release: I've attempted changing my interpreter to every possible option. I've used both Pyenv and Venv (Built-In). I've even switched to to the default 3.10.4 that was installed already on the container. I've insured the packages stating to be failing are installed on all Python versions. It appears there is some kind of disconnect between what VSCode is using as the Interpreter and what Pylint is using. VSCode Settings.json: I added the "python.terminal.activateEnvironment": false, settings based on the advice of other threads I found. These settings are my usual default settings on projects I work outside of Codespaces and don't have any issues. I've even made sure this import works in the actual Python Interpreter. The script runs perfectly fine when I run it normally -- this seems to be strictly a visual error and not an actual error that keeps it from compiling and Interpreted. I've tried many solutions to fix this, but nothing has worked. I've looked at others who reported this issue in the past and none of their solutions helped. I usually do everything I can to avoid submitting issues I know probably have been submitted before, but so far none of those threads have resolved this. Any suggestions? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
QuickstartInstall using pip: AnswersAdd the directory name in front of your filename: I'm not inside the same folder with my app instance, so if I try to run my app with uvicorn I'll get an error like yours. I hope I was able to solve your problem. |
Beta Was this translation helpful? Give feedback.
-
This issue I have managed to fix it. Using ChatGBT I was able to narrow down the issue to the VSCode setting for the path to Pylint being incorrectly pointed at a random Pylint stored inside the /usr directory. After adjusting it to the Pylint in my Pyenv Environment settings and reloading the container. VSCode then re-installed Pylance (No idea why) and then upon a 2nd reload after that the issue is now resolved. I do not understand why this was necessary and why adjusting the interpreter doesn't just override that setting. It has to be that Codespaces is forcefully pointing VSCode at the Pylint stored in /usr For anyone who stumbles across this:
|
Beta Was this translation helpful? Give feedback.
-
I had a similar issue. As I was moving through the steps given in this answer by PancakePuncher, I found the setting "Pylint: Import Strategy". After installing pylint in my virtual environment, I set "Pylint: Import Strategy" to "fromEnvironment" and now the import resolution works correctly. |
Beta Was this translation helpful? Give feedback.
This issue I have managed to fix it.
Using ChatGBT I was able to narrow down the issue to the VSCode setting for the path to Pylint being incorrectly pointed at a random Pylint stored inside the /usr directory.
After adjusting it to the Pylint in my Pyenv Environment settings and reloading the container. VSCode then re-installed Pylance (No idea why) and then upon a 2nd reload after that the issue is now resolved.
I do not understand why this was necessary and why adjusting the interpreter doesn't just override that setting. It has to be that Codespaces is forcefully pointing VSCode at the Pylint stored in /usr
For anyone who stumbles across this: