-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
MyPy cannot find module #1293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
MYPYPATH should be set similarly to how you would set PYTHONPATH. In
your case I presume you've installed py2neo using pip or another
similar way, so Python doesn't need PYTHONPATH; but mypy doesn't know
what Python 2's sys.path looks like (nor should it, really) so you
need to set MYPYPATH. Try to figure out the directory where py2neo is
installed and setting MYPYPATH to that directory.
|
Thanks. When I print |
FWIW, so I'm not blocked I copied the output from
I get this error output:
|
Oh. It looks like setting MYPYPATH like that also finds the stdlib
collections.py instead of the stub for it from typeshed.
It should be easy enough to find out what the path for py2neo -- use
something like `python -c 'import py2neo; print py2neo.__file__'`. I'm
no expert in bash so you'll have to figure out for yourself how to
turn that output into the directory (maybe `dirname`?)
|
Pointing mypy to the standard library is generally not desirable unless typeshed comes first in the search path as then you'll lose type checking on code that uses the std library (there are no annotations in the std library) and also because mypy will generate spurious errors when running against a bunch of std library code that it can't quite handle yet. |
Closing as dupe of #1339. |
I also ran into the traceback above today trying to figure out how to get mypy to work when the Python module dependencies are in a Python 2 virtualenv, using basically |
The crash is not very interesting. We'd like to do better than crashing, of course, but the real issue here is that (probably through setting MYPYPATH equal to PYTHONPATH) mypy is analyzing the real stdlib instead of the stubs from typeshed. This is just not how it's supposed to be used. What were you hoping to get from setting MYPYPATH to your venv's site-packages? You're really much better off living with errors about missing modules, or using -s/--silent-imports. |
It's unlikely that mypy will ever be able to make sense of totally arbitrary library modules, because some modules use dynamic magic to define their contents, and mypy would see nothing, and some modules are implemented in C and, again, mypy can't see inside them. |
Ahh, OK, it turns out I had misdiagnosed an issue. When I ran mypy on a machine that only has the dependency libraries installed in a venv, I got a number of errors like this:
which I had thought were related to effectively
and thinking I needed to have mypy have access to the actual gcmclient to use this But it turns out the cause is instead:
which I can resolve by adding a So I guess I don't need to be setting MYPYPATH here; sorry for the confusion! |
I'm adding MyPy annotations to a single Python 2 file that uses the
py2neo
package, here's what I have so far (just 2 functions annotated). The file is calledgdb.py
.I run MyPy from the terminal in the same directory and virtual-environment as normal Python
> mypy --py2 gdb.py
I get this error output:
I can't find any documentation on how
MYPYPATH
is meant to be set.My
__init__.py
file doesn't contain anything of significance, just futures imports.Python itself works fine -
python gdb.py
runs without any errors when run from the same terminal session asmypy
.The text was updated successfully, but these errors were encountered: