mypy-PyCharm-plugin
mypy-PyCharm-plugin copied to clipboard
Cannot set MYPYPATH
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?
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.
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.
+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.
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
@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 https://github.com/python/mypy/issues/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
).