Skip to content
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

mypy cannot find module installed as editable by pip #7508

Closed
tsoernes opened this issue Sep 13, 2019 · 8 comments
Closed

mypy cannot find module installed as editable by pip #7508

tsoernes opened this issue Sep 13, 2019 · 8 comments

Comments

@tsoernes
Copy link

I have a module installed as editable by pip, i.e. pip install -e ... Mypy cannot import it, even when run as python -m mypy:

feed.py:10: error: Cannot find module named 'rsspull.article'
feed.py:11: error: Cannot find module named 'rsspull.feedparser_types'

~/.config/mypy/config:

[mypy]
mypy_path = '/home/torstein/code/fintechdb/pull/RSSPull/rsspull:/home/torstein/code/fintechdb/pull/RSSPull:/home/torstein/code/fintechdb/:/home/torstein/code/fintechdb/Ftools/ftools:/home/torstein/anaconda3/envs/rss/lib/python3.7/site-packages/'

Installing a module as editable creates an egg link in the virtual env, whatever that is:

$ fd rsspull ~/anaconda3/envs/rss                                                                                              
/home/torstein/anaconda3/envs/rss/lib/python3.7/site-packages/rsspull.egg-link
mypy               0.720     
mypy-extensions    0.4.1 

(I'm running mypy inside of the anaconda virtual env. Python is able to find the module)

@ethanhs
Copy link
Collaborator

ethanhs commented Sep 15, 2019

Does the package have a py.typed file in it as PEP 561 specifies?

@tsoernes
Copy link
Author

@ethanhs I created two blank files py.typed, one in RSSPull (top level directory, i.e. same level as setup.py and one in RSSPull/rsspull (same level as the source code)..

Mypy is still unable to import the rsspull module.

@ethanhs
Copy link
Collaborator

ethanhs commented Sep 16, 2019

I don't think this should matter, but does the setup.py have a zip_safe=False?

@ethanhs
Copy link
Collaborator

ethanhs commented Sep 16, 2019

Also could you try running python -m mypy.sitepkgs?

@tsoernes
Copy link
Author

@ethanhs No to the former.

['/home/torstein/anaconda3/envs/rss/lib/python3.7/site-packages', '/home/torstein/.local/lib/python3.7/site-packages']

@ethanhs
Copy link
Collaborator

ethanhs commented Sep 16, 2019

@tsoernes if you add zip_safe=False to your package, does it work? I can't remember, but I think that may fix it.

See the documentation too https://mypy.readthedocs.io/en/latest/installed_packages.html#making-pep-561-compatible-packages

@tsoernes
Copy link
Author

It certainly does! Thanks a lot.

@ethanhs
Copy link
Collaborator

ethanhs commented Sep 17, 2019

Great! Glad that worked. Maybe we should have a common issues section related to PEP 561 packages not working...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants