2

In a Python file, my first line is:

from flask import Flask

Which triggers an error in the gutter that shows the following message when I drag the cursor over that line:

Cannot find implementation or library stub for module named "flask"

I have installed Flask with Pipenv in a virtual environment. Then I have activated the virtual environment. Running Flask from there works so I assume I have installed it correctly.

I also run Vim from that activated virtual environment:

Running :py3 import sys, site; print('Version:', sys.version); print('Executable:', sys.executable); print('Site Packages:', site.getsitepackages()) returns:

Version: 3.9.6 (default, Jun 30 2021, 10:22:16)                                                                                                                                                                                                              
[GCC 11.1.0]                                                                                                                                                                                                                                                 
Executable: /home/bastien/.local/share/virtualenvs/flask-hxySx92r/bin/python3                                                                                                                                                                                
Site Packages: ['/home/bastien/.local/share/virtualenvs/flask-hxySx92r/lib/python3.9/site-packages'] 

So I understand Vim is correctly running from the virtual environment.

Installing Flask globally and running Vim again does not trigger that error. So I assume the package from the virtual environment cannot be found.

I use ALE, but after investigating, I'm not sure anymore what is responsible for printing those messages.

Also, youcompleteme stops working when running Vim from the virtual environment. I have set the full python path though.

Any help is appreciated.

6
  • Is ALE running mypy? Is that installed in the virtualenv and detected in path earlier than a global mypy?
    – D. Ben Knoble
    Commented Jul 28, 2021 at 13:41
  • ALE is running Black. I have tried to install Black in the virtual environment, outside it and to totally uninstall it. The result is the same, the error message is always there.
    – Bastien
    Commented Jul 28, 2021 at 15:42
  • Huh. I didn't think Black checked for stubs… thought it only formatted… must be out of my experience then. (You're sure? :ALEInfo, for one, though it doesn't consistently show me my LSPs running)
    – D. Ben Knoble
    Commented Jul 28, 2021 at 16:40
  • @D.BenKnoble :ALEInfo returns that mypy is in the list of available linters. So I tried to install it also inside the virtualenv and indeed it works now. Thanks! Would you like to make it a full answer?
    – Bastien
    Commented Jul 28, 2021 at 16:41
  • Although this solves my current issue, I don't really see the value of installing a tool like that inside the virtualenv. I use it on all my projects. To me it's a bit like installing vim inside each project, I don't get what are the benefits.
    – Bastien
    Commented Jul 28, 2021 at 16:47

1 Answer 1

3

As we sussed out in the comments, this is from ALE+mypy, which needs to be installed in the virtual-env of the project.

Why? I'm not 100% sure, but I suspect mypy is simply ignorant of virtual-environments. It probably uses its installation location to find modules (possibly via the file-system; more likely via dynamic import/eval wizardry).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.