Reputation: 445
I have switched from PyCharm to VSCode for Django development. I cannot get rid of the pylint "Unable to import XXXXX pylint(import-error)" errors for my development modules that are not packaged into my venv.
I have gone through about 20+ discussions from google, most of which are stackoverflow. I have tried all the suggestions and think I now know what the problem is - or at least what the workable solution is.
My setup is as follows. I have a venv where I have pip installed various packages. This is what I use for development work with 2 projects. This works fine and VSCode can see it and use it.
My library code sits in a VSCode project and this can be seen and used from my web project because of:
{
"python.pythonPath": "/home/XXXXX/.virtualenvs/YYYYY/bin/python",
"python.autoComplete.extraPaths": [
"/home/XXXXX/dev/VisualStudioCode/repositories/my-library"
]
}
So far so good. But after trying all the suggestions for pylint to find this code, I have come to the conclusion that pylint requires my library to be installed in the venv and I don't want to do that while I am still developing. So basically, all my code works fine and pylint works fine for intellisense and debugging. BUT I have to put up with these pylint errors when I have particular files open. Luckily, when I close the relevant file, the pylint error disappears from the problems list in the VSCode terminal.
Has anybody else reached the same working conclusion?
Upvotes: 2
Views: 3344
Reputation: 445
I found the answer after more google trawling. It's actually in this [PyLint "Unable to import" error - how to set PYTHONPATH? stackoverflow post.
I created the file .pylintrc in my home user folder, and added the lines :
[MASTER]
init-hook='import sys; sys.path.append("/home/XXXXX/dev/VisualStudioCode/repositories/my-library")
to this file. PyLint now finds my library code from my website project.
Thanks to Brian M. Hunt, June 2017.
Upvotes: 1