Fix Python Relative Imports and Auto-completion in VSCode

Fix Python Relative Imports and Auto-completion in VSCode

k0nze

2 года назад

60,183 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Saeed Rahimi
Saeed Rahimi - 09.11.2023 13:40

Awesome, thanks

Ответить
José Henrique
José Henrique - 13.10.2023 20:58

Very very clear

Ответить
Neil Ian Edles
Neil Ian Edles - 25.09.2023 00:43

Thank you!

Ответить
Emre Kara
Emre Kara - 13.09.2023 19:56

What if there is more than one main file that I need to debug in the same folder?

Ответить
Lugares y plantas
Lugares y plantas - 13.09.2023 00:30

Not working for me :/

Ответить
David Perez
David Perez - 29.08.2023 20:47

Thank you for sharing, Very good Job!

Ответить
Mohamad
Mohamad - 15.07.2023 20:49

You are great!

Ответить
ogidog
ogidog - 30.06.2023 07:54

JetBrain Intellij IDEA - FOREVER!!!!!

Ответить
Stanislav Stanislavsky
Stanislav Stanislavsky - 28.06.2023 17:25

I asume, this will work only in VSCode. I.e. if I'll deploy my project somewhere else it won't work.

Ответить
sanket wagh
sanket wagh - 19.06.2023 22:33

that was very helpfull thansks a ton

Ответить
Tapgaze
Tapgaze - 06.06.2023 11:42

how for multiple paths please?

Ответить
Marco Perez
Marco Perez - 17.05.2023 23:20

if you are using a virual env and you've installed the package locally - its best to put below in either your workspace settings file - or maybe even your settings.json file

"python.analysis.extraPaths": [
"${execPath}"
],

Ответить
ShivaKrishna
ShivaKrishna - 12.05.2023 11:12

Do we need to do this everytime we create a project? Is there a way to make vscode automatically add project folder to pythonpath?
Thanks!

Ответить
Róbert Vörös
Róbert Vörös - 13.04.2023 17:59

For the intellisense part I agree.
But the basic problem is not solved with imports because the solution is restricted to VS Code. The script will still not work from command prompt so the antipattern issue is not resolved by this. Path has to be extended... Bad, I agree.
If there's a PEP against it they shouldn't only ban it but offer an acceptable solution too.

Ответить
Lance Barrett
Lance Barrett - 03.04.2023 18:15

❤❤❤

You, sir, are awesome. I’ve been googling how to get my VScode debugger working properly with my project for hours now. Yours was the first to give me a pretty clear understanding of what was happening and how to resolve the issue. (I have my project’s main module 2 layers deep).

Thank you!!!!

Ответить
Lukash Poturai
Lukash Poturai - 26.03.2023 21:55

it is not working

Ответить
Leonid Sokolov
Leonid Sokolov - 28.02.2023 03:36

This helped me a lot working with micropython too (as I need relative imports with sys.path.append on the controller, but want Intellisense when coding). Thanks!

Ответить
TradeMachine
TradeMachine - 28.02.2023 02:04

I found many solutions, but you provided the best of them for both problems ("ModuleNotFoundError" and "Pylance reportMissingImports"). Thank you!

Ответить
Mikhail Khlyzov
Mikhail Khlyzov - 11.02.2023 12:59

As much as I appreciate the explanation and showcase of doing it inside VSCode, the solution feels a bit off imho. I'd rather use editable install of my sub module inside virtual environment (that I use anyway). Would be IDE agnostic.

Ответить
Raj Singh
Raj Singh - 03.02.2023 10:35

I have this same problem with odoo library import tried settings.json and PYTHONPATH settings but it didnot work for me i still get the same import error. can you please help

Ответить
Dharam Parkash Garg
Dharam Parkash Garg - 27.01.2023 09:03

Fix Python Absolute Imports and Auto-completion in VSCode, could you please fix this issue as well

Ответить
Dharam Parkash Garg
Dharam Parkash Garg - 26.01.2023 16:34

Hi I am using Visual Studio 2022 and its very complicated and unable to find solution for same problem. Please help. Even I am unable to find Run & debug icon here.

Ответить
Leviathan
Leviathan - 10.01.2023 01:57

This is very bad advice, as it forces you to run scripts in vscode only.

Ответить
Victor Hugo Cubas Balbuena
Victor Hugo Cubas Balbuena - 28.12.2022 20:20

unfortunately it didn't work for me :(

Ответить
timothé david
timothé david - 23.12.2022 14:03

thanks for all ! I make an anti pattern during several day and now I can work easly :) thanks for all

Ответить
Фёдор Максименков
Фёдор Максименков - 21.11.2022 18:21

absolutely thrash solution

Ответить
raviprasadmr
raviprasadmr - 21.11.2022 00:46

I am new to vscode, and I searched stackoverflow and several other pages to end up getting all the confusing information. I am glad that I found out this channel finally to solve my problems. Thanks much!

Ответить
bar9753
bar9753 - 15.11.2022 17:41

Good explaination!

Ответить
Alexey Matveev
Alexey Matveev - 10.11.2022 19:56

Thanks for the topic, but didn't work for me....(( I'm trying to make import from a parallel directory and it doesn't work(((

Ответить
走るw
走るw - 14.10.2022 19:52

Can't understand why microsoft leave this shit

Ответить
Salar Ghaffarian
Salar Ghaffarian - 17.09.2022 20:33

Much appreciated! That was very helpful!
Thanks!

Ответить
Oskar Hovmøller Dinesen
Oskar Hovmøller Dinesen - 13.09.2022 18:07

Great tutorial! Thanks

Ответить
patite
patite - 20.08.2022 20:22

Great video. But where I know in my case where my_package is? I'm just unable to implement it!

Ответить
Alireza Mohammadi
Alireza Mohammadi - 18.08.2022 12:38

that was great!but I have a question...vs code not showing mysql.connector auto complete suggestions what should I do for that?

Ответить
Dilson VR
Dilson VR - 05.08.2022 16:41

Thanks for this !

Ответить
舒玉帛
舒玉帛 - 31.07.2022 05:41

Awesome!!

Ответить
Milad Pourrahmani
Milad Pourrahmani - 21.07.2022 03:45

I've been putting off fixing VS Code auto-completion for years. Thank you my man!

Ответить
André Knauf
André Knauf - 19.07.2022 20:05

Many thanks man, for this amazing video, it took me hours to get rid of this!

Ответить
Kumar Vishal
Kumar Vishal - 28.06.2022 06:18

helpful , simple to the point ..

Ответить
Men Among the Ruins
Men Among the Ruins - 27.06.2022 12:42

fixed it sub

Ответить
Sudarshan Koirala
Sudarshan Koirala - 31.05.2022 21:43

Short and clear explanation .. keep making these sort of videos .. thank you !

Ответить
MultiMediaUploads
MultiMediaUploads - 28.05.2022 11:30

This is a suboptimal solution that works locally, and forces anyone that works on this project to use vscode as their IDE. The best solution is to package the extern directory as its own package and have it part of the requirements for the project, and then you can import it from there. Unfortunately, you are trying to fix an anti-pattern by promoting another one.

Ответить
N S
N S - 20.05.2022 00:57

Would this solution work if someones else tries to use our project using another IDE, let's say Pycharm?

Ответить
James Dooley
James Dooley - 11.05.2022 02:10

Sorry but this is nonsense! Your entire project is now dependent on the IDE you use and if you were actually working with colleagues they would not be able to work with your project without also using the same editor. If you are using package and the loading mechanism correctly there should be no need to resort to this kind of nonsense. You do people no favors by promoting this kind of stuff.

Ответить
Václav Brožík
Václav Brožík - 07.05.2022 17:43

Doing multiple settings just to help VS Code and nothing else? I think it is much better to turn extern into a proper package and install it using pip (could be an "editable" install for easier development) then it will work everywhere, not just in VS Code.

Ответить
CCLK
CCLK - 02.05.2022 17:26

Subscribed! Really great video that saves my life!!
I have two questions.
1)What if I have multiple modules in the same folders that need the extended python path (or multiple extended python paths), can I just put the name of the second module after the first one?
2) It was fine for me to run the file under VS code and import the module from another directory. However, why did it still complains ModuleNotFoundError when I executed the python file via Terminal?

Ответить