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

Cannot set MYPYPATH #14

Open
petergaultney opened this issue Jul 20, 2018 · 5 comments
Open

Cannot set MYPYPATH #14

petergaultney opened this issue Jul 20, 2018 · 5 comments

Comments

@petergaultney
Copy link

Thanks for this plugin - it's nice to have this running constantly inside PyCharm.

There may be a way to do this, but it's not in the README as far as I could tell, so I thought I'd bring this up.

For those of us who want to use types that exist outside our current project, it is nice to be able to --follow-imports silent. However this just leads to handler.py:2: error: Cannot find module named 'botocore.vendored' or whatever the module is.

When running from the command line, I can just add my VENV site-packages dir to the environment variable MYPYPATH and everything works great. However I'm not sure how to usefully define an env var for this plugin. More importantly, it really needs to be something that the plugin can figure out based on some kind of config file, e.g. the mypy.ini config file in the project root. However, setting mypy_path inside that config file does not seem to get picked up by this plugin.

Any thoughts on how to make this work properly?

@ilevkivskyi
Copy link
Contributor

Thanks for reporting! Could you please clarify what exactly did you try? I could imagine two possible ways (right click in plugin window and then chose "Configure plugin..."):

  • Try to prefix your command with MYPYPATH=your/lib/path
  • Add something like --config-file=your_conf.ini in the command

Please let me know if this works, and I will update the README later when I am back from vacation.

@petergaultney
Copy link
Author

I will try both of those. I actually already suspected that the first one, at least, should work fine. The only problem is that then it's part of the IDE setup instead of part of the code configuration, which makes getting new developers spun up on an existing repository somewhat harder.

What I tried was putting config in the mypy config file at the project root according to the instructions here: http://mypy.readthedocs.io/en/stable/config_file.html However, it seems that either their documentation is wrong, or else this plugin does not start up the mypy daemon with the project root as the working directory, so mypy never sees the config file.

I could also set this up as global mypy config, except that different projects use different VENVs, so the correct mypy path varies and isn't properly a system-global variable.

I'll report back on your suggestion.

@00krishna
Copy link

+1
In order to find installed modules or packages in a virtual environment--in my case an Anaconda environment--the MYPYPATH environment variable needs to be configured. But there does not seem to be a smooth way for Pycharm to run this upon startup of a project.

There is a functionality to add environment variables in a run configuration, but the mypy plugin is working through a run configuration.

Any ideas would be helpful. Otherwise the use would have to manually run the export of MYPYPATH each time they use the system. Or they just have to disable checking for packages.

@rommguy
Copy link

rommguy commented Nov 21, 2019

I'm had the same problem.
After some searching, I found that the plugin uses dmypy (mypy server).
According to dmypy documentation, dmypy is unable to follow imports, regardless of the environment parameters that specify where module can be.

If you want to follow imports, you need to open the plugin configuration and replace the mypy command to run mypy instead of dmypy - than the default becomes "follow-imports=normal" and the MYPYPATH will be used to find modules.
You should consider that this will make the plugin run slower than with dmypy

@ilevkivskyi I think you can close this issue since it is a limitation of dmypy and not an issue of your plugin

@ilevkivskyi
Copy link
Contributor

@rommguy

I think you can close this issue since it is a limitation of dmypy and not an issue of your plugin

Hm, so essentially this is caused by python/mypy#5870. I would keep this open until upstream is fixed. We might need to update the default config when upstream is fixed (currently it is --follow-imports=error).

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

4 participants