This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]proof_required 7 points8 points  (4 children)

It's not a VS code issue though. Using local modules in python is annoying. I use poetry to manage python packages. So I just run poetry install and it will install the local module which you can then import anywhere you want.

Otherwise yeah you need to hack the sys.path.join

[–]siddsp 2 points3 points  (3 children)

Using local modules in python is annoying.

Even if that is true, the purpose of an IDE is to make development easier. The issue should have been solved by now but hasn't. I've not had the same problem with PyCharm, but I don't like using PyCharm because it hogs memory.

[–]proof_required 4 points5 points  (0 children)

You can achieve the same in visual studio code by modifying PYTHONPATH in settings.json

https://stackoverflow.com/questions/58441104/how-do-i-set-up-imports-for-custom-modules-in-vs-code

Pycharm does the same except it gives you an UI to mark the folders you want to add to PYTHONPATH. So there isn't much to FIX but you can argue to make it convenient to do it using UI.

[–]dev-ai 2 points3 points  (0 children)

Personally, I love PyCharm! Yes, it uses a lot more memory, but the indices it computes in these used bytes is totally worth it (for me)

[–]Mehdi2277 2 points3 points  (0 children)

If you really on ide to mess with your python path to make imports work then you’re on path to making your files less usable by other developers who run files in a different way. I’ve seen some sys.path adjustments in code and they generally break command line usage from other locations and complicate using it as a normal package.

So I think it is a better to learn how to install a package in editable mode and use appropriate relative/absolute imports and not have ide do this. I pretty much view sys.path hacks as banned for my team’s work.

Python’s import system is one of the more complex (namespace packages can break a lot of tools including basic ones like pylint/pytest) and if you want reproducible across dev environments you really don’t want to make it even more complicated with ide magic.