Reputation: 661
I downloaded and installed mypy together with its dependencies to a folder called lib (where apart form mypy other libraries are situated, too):
pip install --upgrade --target=. mypy
Collecting mypy
Using cached mypy-0.790-cp37-cp37m-win_amd64.whl (8.5 MB)
Collecting mypy-extensions<0.5.0,>=0.4.3
Using cached mypy_extensions-0.4.3-py2.py3-none-any.whl (4.5 kB)
Collecting typed-ast<1.5.0,>=1.4.0
Using cached typed_ast-1.4.1-cp37-cp37m-win_amd64.whl (155 kB)
Collecting typing-extensions>=3.7.4
Using cached typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
Installing collected packages: mypy-extensions, typed-ast, typing-extensions, mypy
Successfully installed mypy-0.790 mypy-extensions-0.4.3 typed-ast-1.4.1 typing-extensions-3.7.4.3
I would like to analyze a file with mypy that imports modules from a different directory (namely the lib-module I installed mypy in). So in order to follow the imports I set the MYPYPATH variable to hold the path to the lib-directory:
set MYPYPATH=path_to_lib
Now if I execute mypy I get an error that '"typing_extensions.py" shadows library module "typing_extensions"':
mypy --namespace-packages script_to_check.py
mypy: "path_to_lib\typing_extensions.py" shadows library module "typing_extensions"
note: A user-defined top-level module with name "typing_extensions" is not supported
typing_extensions was actually installed by mypy and now it tells me that it cannot use the package!?
If I rename typing_extensions.py in pyth_to_lib to _typing_extensions.py I get an error that typing_extensions cannot be imported by mypy:
mypy --namespace-packages ng_gen_igxl_tp.py
Traceback (most recent call last):
File "c:\software\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\software\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "path_to_lib\bin\mypy.exe\__main__.py", line 4, in <module>
File "path_to_lib\mypy\__main__.py", line 4, in <module>
from mypy.main import main
File "mypy\main.py", line 11, in <module>
ModuleNotFoundError: No module named 'typing_extensions'
How do I get mypy to run?
Upvotes: 4
Views: 3718
Reputation: 661
After further investigations what I already mentioned in the comment proves to be true: It is not possible to include the directory where mypy is installed in MYPYPATH
.
I ended up creating a virtual environment and installing mypy in there - which we should have done in the first place - and now everything runs as it's supposed to.
Upvotes: 3