mypy-pycharm icon indicating copy to clipboard operation
mypy-pycharm copied to clipboard

MacOS: Error while checking Mypy path

Open kupuguy opened this issue 6 years ago • 15 comments

Step 1: Are you in the right place?

  • [X] I have verified there are no duplicate active or recent bugs, questions, or requests
  • [x] I have verified that I am using the latest version of the plugin.

Step 2: Describe your environment

  • Plugin version: 0.10.2
  • PyCharm/IDEA version: 2018.3.4 Build #PY-183.5429.31
  • Mypy version: 0.620

Step 3: Describe the problem:

Steps to reproduce:

  1. Install mypy using brew install mypy
  2. Restart pycharm

Observed Results:

  • Pycharm indicates a fatal error "Error while checking Mypy path"

Expected Results:

  • Pycharm should load without complaining

Relevant Code:

I think the plugin is throwing an error when executing the /usr/local/bin/mypy file as installed by brew but I can't see why. This file contains:

#!/bin/bash
PYTHONPATH="/usr/local/Cellar/mypy/0.620/libexec/lib/python3.7/site-packages:/usr/local/Cellar/mypy/0.620/libexec/vendor/lib/python3.7/site-packages" exec "/usr/local/Cellar/mypy/0.620/libexec/bin/mypy" "$@"
java.lang.Throwable: Error while checking Mypy path:   File "/usr/local/bin/mypy", line 2
    PYTHONPATH="/usr/local/Cellar/mypy/0.620/libexec/lib/python3.7/site-packages:/usr/local/Cellar/mypy/0.620/libexec/vendor/lib/python3.7/site-packages" exec "/usr/local/Cellar/mypy/0.620/libexec/bin/mypy" "$@"
                                                                                                                                                             ^
SyntaxError: invalid syntax
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:134)
	at com.leinardi.pycharm.mypy.mpapi.MypyRunner.isMypyPathValid(MypyRunner.java:102)
	at com.leinardi.pycharm.mypy.mpapi.MypyRunner.checkMypyAvailable(MypyRunner.java:176)
	at com.leinardi.pycharm.mypy.mpapi.MypyRunner.checkMypyAvailable(MypyRunner.java:152)
	at com.leinardi.pycharm.mypy.MypyInspection.inspectFile(MypyInspection.java:76)
	at com.leinardi.pycharm.mypy.MypyInspection.lambda$checkFile$0(MypyInspection.java:65)
	at com.intellij.openapi.application.impl.ApplicationImpl$2.call(ApplicationImpl.java:337)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

image

kupuguy avatar Feb 11 '19 10:02 kupuguy

I see a similar problem on OSX using the path of mypy inside my project's venv, using Intellij with the python plugin

Daenyth avatar Feb 11 '19 16:02 Daenyth

I looked at the code. Until the last change it looked like:

        GeneralCommandLine cmd = new GeneralCommandLine(pathToMypy);
        if (daemon) {
            cmd.addParameter("status");
        } else {
            cmd.addParameter("-V");
        }

The latest version is:

        GeneralCommandLine cmd = getMypyCommandLine(project, mypyPath);
        boolean daemon = false;
        if (daemon) {
            cmd.addParameter("status");
        } else {
            cmd.addParameter("-V");
        }

Where getMypyCommandLine() is:

    private static GeneralCommandLine getMypyCommandLine(Project project, String mypyPath) {
        GeneralCommandLine cmd;
        VirtualFile interpreterFile = getInterpreterFile(project);
        if (interpreterFile == null || FileTypes.isWindowsExecutable(mypyPath)) {
            cmd = new GeneralCommandLine(mypyPath);
        } else {
            cmd = new GeneralCommandLine(interpreterFile.getPath());
            cmd.addParameter(mypyPath);
        }
        return cmd;
    }

So where previously the code used the filename e.g. /usr/local/bin/mypy and just executed it, now it will get the current Python interpreter for the project and run it with the mypy command as an argument. As the mypy command is a bash script this produces the syntax error. Even if I am using a virtualenv with and pip install mypy locally, the mypy command is still a bash script.

kupuguy avatar Feb 12 '19 09:02 kupuguy

FYI I am getting the same error on Ubuntu Linux 18.04, Pycharm 2018-03-05, Mypy 0.67, Mypy plugin version 0.10.2. Seems like the path is not getting detected.

java.lang.Throwable: Mypy path detect process.exitValue: 1
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:134)
	at com.leinardi.pycharm.mypy.mpapi.MypyRunner.detectSystemMypyPath(MypyRunner.java:216)
	at com.leinardi.pycharm.mypy.mpapi.MypyRunner.getMypyPath(MypyRunner.java:146)
	at com.leinardi.pycharm.mypy.mpapi.MypyRunner.getMypyPath(MypyRunner.java:124)
	at com.leinardi.pycharm.mypy.mpapi.MypyRunner.checkMypyAvailable(MypyRunner.java:176)
	at com.leinardi.pycharm.mypy.mpapi.MypyRunner.checkMypyAvailable(MypyRunner.java:152)
	at com.leinardi.pycharm.mypy.MypyInspection.inspectFile(MypyInspection.java:76)
	at com.leinardi.pycharm.mypy.MypyInspection.lambda$checkFile$0(MypyInspection.java:65)
	at com.intellij.openapi.application.impl.ApplicationImpl$2.call(ApplicationImpl.java:337)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

00krishna avatar Mar 11 '19 17:03 00krishna

image I had the same error on Windows 10 Pycharm community 2018.3.5

pplmx avatar Mar 29 '19 00:03 pplmx

I had this issue with pyenv with both python 2.7 and python 3.7 installed. Once I was able to resolve down to a single version I was able to take the output of pyenv which mypy and paste it into the path to mypy executable (preferences/mypy) and everything worked fine.

tj800x avatar Apr 14 '19 16:04 tj800x

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

stale[bot] avatar Jun 13 '19 16:06 stale[bot]

I have an almost identical situation...

Mac OS 10.13.6
PyCharm 2019.2.1 Preview (Professional Edition)
Build #PY-192.6262.12, built on August 6, 2019
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
mypy plugin version 0.10.4
Python version 2.7.15

I installed mypy via brew, so mypy in installed in: /usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/bin/mypy.

I created a symbolic link to it in /usr/local/bin like this:

% ls -l /usr/local/bin/mypy
lrwxr-xr-x  1 xyzzy  admin  80 Aug 15 15:50 /usr/local/bin/mypy -> /usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/bin/mypy

The configuration for the plugin is:

Screen_Capture_2019-08-15_at_4 00 14_PM

It even shows that it auto-detected /usr/local/bin/mypy. But when I click test I get an error:

java.lang.Throwable: Error while checking Mypy path: Traceback (most recent call last):
  File "/usr/local/bin/mypy", line 6, in <module>
    from mypy.__main__ import console_entry
ImportError: No module named mypy.__main__
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:145)
	at com.leinardi.pycharm.mypy.mpapi.MypyRunner.isMypyPathValid(MypyRunner.java:103)
	at com.leinardi.pycharm.mypy.ui.MypyConfigPanel$TestAction.actionPerformed(MypyConfigPanel.java:115)

This happened even when I didn't use a symbolic link to mypy, but instead put the full path in the configuration.

EricRFMA-ES avatar Aug 15 '19 20:08 EricRFMA-ES

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

stale[bot] avatar Oct 14 '19 20:10 stale[bot]

I've used this plugin for a long time but after updating today I can't get it to work anymore with mypy installed via homebrew or conda. It can't detect the executable.

soleares avatar Feb 04 '20 17:02 soleares

@soleares could you please downgrade the the previous version and confirm that is actually a regression? https://github.com/leinardi/mypy-pycharm/releases/tag/0.10.6

leinardi avatar Feb 04 '20 17:02 leinardi

I found a regression. Just published version 0.11.1. It's waiting Jetbrains approval, but can be installed manually from here: https://github.com/leinardi/mypy-pycharm/releases/tag/0.11.1 @soleares it would be nice if you could confirm that this version fixes the regression for you.

leinardi avatar Feb 04 '20 18:02 leinardi

@leinardi It looks like it's not a regression. It's not working for me in all 3 versions. I can only get it to work if I install mypy in the project's virtualenv and use that in the settings.

Steps to reproduce:

  • brew install mypy
  • Create new project in pycharm with default virtualenv.
  • Go to mypy settings
  • Set 'Path to mypy executable' to /usr/local/bin/mypy
  • Click 'Test'

soleares avatar Feb 04 '20 20:02 soleares

this is intended: mypy must be installed in the same environment that PyCharm is using for the project.

leinardi avatar Feb 04 '20 20:02 leinardi

Got it, thanks for clarifying this!

soleares avatar Feb 04 '20 21:02 soleares

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

stale[bot] avatar Apr 04 '20 21:04 stale[bot]