-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Python unresolved import issue returns #5518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Please inform if you are using Language server or jedi, i.e check the value of setting |
@AlexLemna Please inform if you are using Language server or jedi, i.e check the value of setting python.jediEnabled in settings.json. |
python.jediEnabled is not present in the settings.json. So I believe it defaults to true, which is, jedi as the IntelliSense engine. |
I'm really inexperienced and it's possible I've set something up wrong, but I'm getting similar errors. @karrtikr Environment data:
DescriptionMy files are in a directory like this:
where my main file For what it's worth, I get similar (but slightly different?) errors in regular Visual Studio. Either way, the code runs fine! It's just weird. |
No worries, i'll help you do it. @roubles @AlexaLemma Can both of you please provide the following logs mentioned in the template:
|
@AlexLemna As for your issue, Please check this comment and this solution. Basically python doesn't know where to look for modules by default, when you import. You have to specify the folder, in your case you need to create an |
@karrtikr Thanks, that fixed it! I had tried the suggestions in those comments earlier, but I made the mistake of literally copy-pasting from those suggestions instead of adjusting it for my project's actual directory structure.
Basically, I had Just out of curiosity - will I need to add a second (Also - do you still need my logs now that my issue is resolved? Sorry for not including them - I'll check the template next time.) |
Although remember, the way of concatenating environment variables is platform dependent. See this. |
@roubles Please confirm if you have |
Ok, so here is what I have. Under .vscode/settings.json
Let me know if any of this is not needed or superfluous. In my project root folder I have .env
Here are the logs from Output panel:
For now, I am going back to PyCharm. This usecase works out of the box in PyCharm, and it should work of the box in VSCode as well. |
Can you please also provide details for |
Hi, I don't want to hijack the thread, but I've the same problem, and I don't get (at all) the comments about the PYTHONPATH, in my case I use pipenv, but should be the same as author virtualenv, the 3rd party libraries in the environment are detected, so the PYTHONPATH should be ok and my own package is installed in the env (pip(env)-e .). I can open a new bug but it sounds to me that the same (2months long, now) bug. LanguageServer or jedi have the same problem (tried both) |
Hi @potens1 ,
You have to explicitly set In that case, I would like if you could please open up on a new issue specifying your details separately. |
Hi, thx for your answer, |
Hi, I have a very simple setup where I have a bunch of Python files in the same directory, but importing one gives the same error reported here. Works fine when I run the program. It seems strange that files in the same folder cannot be imported. PyCharm by the way has no problem with it. Update: I had to add .env file in the project folder and define PYTHONPATH |
Hi @dibyendumajumdar , there's a open issue #5710 to track this. Will be addressed soon enough. Current scenario is that we have to explicitly set |
@karrtikr Sure but I shouldn't need to get this info from an issue - strange that all the videos and articles about getting started with Python don't mention this upfront. Maybe because everyone demos editing a single file. |
Yes, i understand. Ideally you should not need to get this info from an issue. |
I have been unable to get
{
"folders": [{ "path": "a" }, { "path": "b" }],
"settings": {
"python.pythonPath": "${workspaceFolder}/.venv/bin/python",
"python.envFile": "${workspaceRoot}/.env"
}
}
I know that before yesterday I had a setup where each folder simply had a I've tried downgrading, using absolute paths, using a |
Ok! I got everything to work with the latest by enabling jedi in user settings ( For my multi-root environment, this is the setup that ended up working with jedi (including go-to definition, analysis, autocomplete): Functioning Multi-Root setup with
|
@micimize Glad you got it working for now. Although, it should be working with |
If the solution stated in the thread does not work for people, please to open up a new separate issue, as issues could be unrelated. |
Closing until further info is provided |
Uh oh!
There was an error while loading. Please reload this page.
Environment data
Description
My code references imports from a virtual environment as follows:
In my settings.json I have my pythonPath setup to use that virtualenv:
The virtualenv is setup correctly, and my code runs from the command line. However, within vscode I get "unresolved import" warnings for any imports from the virtualenv.
I have tried the workaround listed on this, now closed, defect: #3840
Workaround: #3840 (comment) -- No dice.
Expected Behavior
No 'unresolved import' warnings since the libraries exist in the virtualenv and the code runs fine on the command line.
Actual behaviour
Tonnes of 'unresolved import' warnings
Steps to reproduce:
Write code that references imports from a virtualenv virtual environment as follows:
In your settings.json set your pythonPath to use that virtualenv:
Thats it. This very setup works on mac, and does not work on linux.
The text was updated successfully, but these errors were encountered: