Repository: python/mypy

Issue:
Running mypy and managing imports and incompatible stubs
**Documentation**

From the [Library stubs not installed](https://mypy.readthedocs.io/en/stable/running_mypy.html#library-stubs-not-installed) section of Running mypy and managing imports:

> You can resolve the issue by running the suggested pip command or commands. Alternatively, you can use [--install-types](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-install-types) to install all known missing stubs [...]

This is incomplete, as it only addresses the issue of missing stubs.

In my case, the issue is that the stubs are not compatible with Python 3.10. I'm confirming this by trying to use Python 3.8, in which case the error disappears and type checking works.

However, I have no idea about what any of that means or entails, as, to the best of my documentation-searching abilities, it's not documented. What makes stubs to be incompatible with a particular Python version? I think that should be documented and referenced in the aforementioned section.

(Stubs not installed and incompatible stubs should also probably separated into two different error states, as for incompatile stubs the advice in the notes is irrelevant and confusing, but this is probably beyond this bug report)


Discussion:
What makes the stubs incompatible? What issues are you seeing? Generally stubs should work with any Python 3 version.
That's also my thinking, that's what's so confusing about that error message.

Quick repro steps (assumes you're running Python 3.10):
```
mkdir empty-dir && cd empty-dir
python -m venv venv
source venv/bin/activate
pip install requests types-requests
echo "import requests" > app.py
mypy app.py
```

Results in:
```
app.py:2: error: Library stubs not installed for "requests" (or incompatible with Python 3.10)
app.py:2: note: Hint: "python3 -m pip install types-requests"
app.py:2: note: (or run "mypy --install-types" to install all missing stub packages)
app.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
```
You need to install types-requests in the environment that mypy is installed in, or point mypy to the correct environment using e.g. `--python-executable venv/bin/python`
@hauntsaninja is right. But maybe we should remove the "(or incompatible with Python 3.10)" part from the error; I'm not really sure when that would be helpful.
Thank you for your clarifications. I don't agree that the issue should be closed, as this still looks to me like a documentation issue. I will give some additional context to clarify my point of view.

I see how my Python 3.8 testing methodology was flawed from @hauntsaninja's comment (and thus why it worked when I tested it with Python 3.8). However:

1) I agree with @JelleZijlstra's remark that it would be useful to clarify that error message to reflect the actual potential error states it represents
2) Since I was 100% positive I had that package in my current environment, and I had read on the documentation that's what was needed (and the note is not suggesting anything different), it seemed pointless to me to run `mypy --install-types app.py` - so I didn't. The link contained in the note wasn't even about my specific issue, so it didn't help convincing me to do that.

[Here](https://mypy.readthedocs.io/en/stable/installed_packages.html), which is what I was referring to in point (2), the following is mentioned:

> Typically mypy will automatically find and use installed packages that support type checking or provide stubs. This requires that you install the packages in the Python environment that you use to run mypy.

The way I understand this, and I don't think it's unreasonable, is: you need the stubs in the venv where you're running mypy from. A better phrasing, in my opinion, would be something like:

> Typically mypy will automatically find and use installed packages that support type checking or provide stubs. This requires that you install the packages in the Python environment where you have installed mypy (which might be different from the current Python environment)

Resolving patch:
diff --git a/mypy/build.py b/mypy/build.py
--- a/mypy/build.py
+++ b/mypy/build.py
@@ -2731,8 +2731,7 @@ def module_not_found(
     else:
         daemon = manager.options.fine_grained_incremental
         msg, notes = reason.error_message_templates(daemon)
-        pyver = "%d.%d" % manager.options.python_version
-        errors.report(line, 0, msg.format(module=target, pyver=pyver), code=codes.IMPORT)
+        errors.report(line, 0, msg.format(module=target), code=codes.IMPORT)
         top_level, second_level = get_top_two_prefixes(target)
         if second_level in legacy_bundled_packages:
             top_level = second_level
diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py
--- a/mypy/modulefinder.py
+++ b/mypy/modulefinder.py
@@ -89,9 +89,7 @@ def error_message_templates(self, daemon: bool) -> tuple[str, list[str]]:
             )
             notes = [doc_link]
         elif self is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED:
-            msg = (
-                'Library stubs not installed for "{module}" (or incompatible with Python {pyver})'
-            )
+            msg = 'Library stubs not installed for "{module}"'
             notes = ['Hint: "python3 -m pip install {stub_dist}"']
             if not daemon:
                 notes.append(


Test patch:
diff --git a/test-data/unit/fine-grained-modules.test b/test-data/unit/fine-grained-modules.test
--- a/test-data/unit/fine-grained-modules.test
+++ b/test-data/unit/fine-grained-modules.test
@@ -2198,11 +2198,11 @@ import waitress
 [file a.py.3]
 import requests
 [out]
-a.py:1: error: Library stubs not installed for "waitress" (or incompatible with Python 3.7)
+a.py:1: error: Library stubs not installed for "waitress"
 a.py:1: note: Hint: "python3 -m pip install types-waitress"
 a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
 ==
 ==
-a.py:1: error: Library stubs not installed for "requests" (or incompatible with Python 3.7)
+a.py:1: error: Library stubs not installed for "requests"
 a.py:1: note: Hint: "python3 -m pip install types-requests"
 a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test
--- a/test-data/unit/pythoneval.test
+++ b/test-data/unit/pythoneval.test
@@ -1562,7 +1562,7 @@ from scribe import x
 import maxminddb  # Python 3 stubs available for maxminddb
 import foobar_asdf
 [out]
-_testIgnoreImportIfNoPython3StubAvailable.py:4: error: Library stubs not installed for "maxminddb" (or incompatible with Python 3.7)
+_testIgnoreImportIfNoPython3StubAvailable.py:4: error: Library stubs not installed for "maxminddb"
 _testIgnoreImportIfNoPython3StubAvailable.py:4: note: Hint: "python3 -m pip install types-maxminddb"
 _testIgnoreImportIfNoPython3StubAvailable.py:4: note: (or run "mypy --install-types" to install all missing stub packages)
 _testIgnoreImportIfNoPython3StubAvailable.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
@@ -1574,7 +1574,7 @@ import maxminddb
 [out]
 _testNoPython3StubAvailable.py:1: error: Cannot find implementation or library stub for module named "scribe"
 _testNoPython3StubAvailable.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
-_testNoPython3StubAvailable.py:3: error: Library stubs not installed for "maxminddb" (or incompatible with Python 3.7)
+_testNoPython3StubAvailable.py:3: error: Library stubs not installed for "maxminddb"
 _testNoPython3StubAvailable.py:3: note: Hint: "python3 -m pip install types-maxminddb"
 _testNoPython3StubAvailable.py:3: note: (or run "mypy --install-types" to install all missing stub packages)