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

Unable to configure mypy binary on Linux

Open MarcinOrlowski opened this issue 6 years ago • 19 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.2.4 (CE)
  • Mypy version: 0.641

Step 3: Describe the problem:

Steps to reproduce:

  1. I am using Ubuntu/Debian based distro
  2. I have both python2 and python3 installed
  3. Installed python3-pip
  4. installed mypy using pip3 install mypy
  5. Properly installed in /usr/local/bin/mypy
  6. above path is in $PATH
  7. mypy runs when started from shell
  8. Attempt to configure your plugin with either mypy or /usr/local/bin/mypy as mypy binary does not work (test fails) with Mypy Plugin: Failure: executable "mypy" not found.

This looks similar to #12

MarcinOrlowski avatar Nov 09 '18 18:11 MarcinOrlowski

Similar issue here, with pycharm generated stacktrace:

2018-11-10T13:11:22.487
java.lang.Throwable: Error while checking Mypy path:   File "/home/will/.pyenv/shims/mypy", line 3
    [ -n "$PYENV_DEBUG" ] && set -x
                      ^
SyntaxError: invalid syntax
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:123)
	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)

flowersw avatar Nov 10 '18 20:11 flowersw

@MarcinOrlowski, @flowersw could you please attach the idea.log file (https://intellij-support.jetbrains.com/hc/en-us/articles/207241085-Locating-IDE-log-files) after you get the Exception?

@MarcinOrlowski which interpreter are you using in PyCharm? The system one or a venv?

leinardi avatar Nov 11 '18 09:11 leinardi

Here's my stacktrace

java.lang.Throwable: Error while checking Mypy path: Traceback (most recent call last):
  File "/usr/local/google/home/orlowskim/mypy", line 7, in <module>
    from mypy.__main__ import console_entry
ImportError: No module named mypy.__main__
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:123)
	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)

I am using 2.7 via venv

MarcinOrlowski avatar Nov 27 '18 20:11 MarcinOrlowski

I ran into a similar issue, it was because it was using the python binary in my venv to execute the global mypy installed with pip3. I had to install mypy in my venv and then I had to provide the path to that mypy in the "Path to Mypy executable" setting.

hackalyze avatar Dec 07 '18 12:12 hackalyze

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

stale[bot] avatar Feb 05 '19 14:02 stale[bot]

I ran into the same problem on MacOS 10.13. In my case the error is:

2019-04-24 23:07:29,098 [ 586314]   INFO - .pycharm.mypy.mpapi.MypyRunner - Command Line string: /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /usr/local/bin/mypy -V 

Why is the plugin using a python interpreter instead of just invoking mypy using the provided path and deferring to the python executable it was installed with? Trying to guess at another interpreter is just asking for trouble. In my case it's using python2, which obviously isn't going to work.

chadrik avatar Apr 25 '19 06:04 chadrik

It seems like a lot of people are running into this same basic problem. Issues #18 and #26 are basically the same.

chadrik avatar Apr 25 '19 06:04 chadrik

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

stale[bot] avatar Jun 24 '19 07:06 stale[bot]

Yeah, not working on Mint either ... Installed mypy using pipx (so just a virtualenv)

$ /home/myusernamehere/.local/pipx/venvs/mypy/bin/mypy
usage: mypy [-h] [-v] [-V] [more options; see below]
            [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
mypy: error: Missing target module, package, files, or command.

Direct copy & paste /home/myusernamehere/.local/pipx/venvs/mypy/bin/mypy does not work.

Edit:

Looks like it's trying to use the projects virtualenv, not the one created by pipx where mypy is installed in ..

path: /home/usernamehere/.virtualenvs/projectnamehere/bin/python: can't find '__main__' module in '/home/usernamehere/projects/projectnamehere/' 
java.lang.Throwable: Error while checking Mypy path: /home/usernamehere/.virtualenvs/projectnamehere/bin/python: can't find '__main__' module in '/home/usernamehere/projects/projectnamehere/'
	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.mpapi.MypyRunner.checkMypyAvailable(MypyRunner.java:177)
	at com.leinardi.pycharm.mypy.mpapi.MypyRunner.checkMypyAvailable(MypyRunner.java:153)
	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:339)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

Edit2:

Installing mypy in project venv resolved the issue, but it should work from elsewhere too ..

paranoidi avatar Jul 02 '19 07:07 paranoidi

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

stale[bot] avatar Sep 16 '19 13:09 stale[bot]

I had similar issue, but in reverse order. I installed mypy via pip in my virtual environment and pycharm gave the error "executable not found". I then installed mypy in my actual environment and then the plugin started working in pycharm.

In short, I had to install mypy in both the venv and the regular environment to get the plugin working.

bandophahita avatar Nov 14 '19 18:11 bandophahita

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

stale[bot] avatar Jan 13 '20 18:01 stale[bot]

This managed to fix the issue for me. I belive my pipenv enviroment appears twice in PyCharm. When I select the second one (see screenshot), it even automatically detected the package. image

sitnarf avatar Jun 19 '20 16:06 sitnarf

For some reason I had to do @sitnarf's suggestion as well, and not just set the project interpreter in PyCharm's project settings. This might be because I had to destroy and update my venv recently, and PyCharm didn't seem to fully propagate that through in a few places. This might have just been a fallout from the same not-propagating.

phoenixeliot avatar Nov 18 '20 22:11 phoenixeliot

in my case, i tried running mypy from the terminal which had the env activated and it wasn't working there either, saying I must install typed-ast for it to work. this is the output:

❯❯❯ mypy setup.py
The typed_ast package is not installed.
You can install it with `python3 -m pip install typed-ast`.
❯❯❯ python3 -m pip install typed-ast                                                                                                                                                                                                                ✘ 1 
Collecting typed-ast
  Downloading typed_ast-1.5.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (843 kB)
     |████████████████████████████████| 843 kB 1.5 MB/s            
Installing collected packages: typed-ast
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
mypy 0.910 requires typed-ast<1.5.0,>=1.4.0; python_version < "3.8", but you have typed-ast 1.5.1 which is incompatible.
astroid 2.6.2 requires typed-ast<1.5,>=1.4.0; implementation_name == "cpython" and python_version < "3.8", but you have typed-ast 1.5.1 which is incompatible.
Successfully installed typed-ast-1.5.1
❯❯❯ mypy setup.py
mypy: can't read file 'setup.py': No such file or directory```

aggo avatar Jan 11 '22 13:01 aggo

Looking into the logfile of pycharm i found out that the plugin is using another pipenv environment that doesnt have mypy instead of using the one pycharm is set on.

2022-01-22 17:43:57,883 [ 574664]   INFO - .pycharm.mypy.mpapi.MypyRunner - Command Line string: /home/CCC/.local/share/virtualenvs/XXX-I8024MuH/bin/python /home/XXX/.local/share/virtualenvs/YYY-LWz7hkGd/bin/mypy -V 

so i simply deleted the XXX environment to force it to use the YYY environment and it solved the issue for me. this page helped me find the log file.

5cat avatar Jan 22 '22 09:01 5cat

Is there any reason why MyPy has to be installed in the project's virtualenv? Why can't it just be called as a binary, without using the project interpreter?

In my case, using the project interpreter makes no practical sense. I have 10+ projects opened at once (in the same window), each has its own virtualenv and project interpreter.

  1. I don't want to install MyPy 10+ times (what for?)
  2. I want to run checks across all open projects, not once for each project by changing the project interpreter every time

This reliance on the project interpreter makes this plugin (as well as the PyLint plugin by the same author) effectively useless for me, unfortunately.

derula avatar Apr 26 '23 08:04 derula

If I recall correctly, it was done to be sure that the installation of mypy/pylint has access to the same dependencies of the project, otherwise it may lead to false positive.

If someone wants to try to improve this, PRs are welcome.

leinardi avatar Apr 26 '23 08:04 leinardi

Hmm, that reasoning actually makes sense assuming that mypy, like pylint, doesn't support separating its own dependencies from the project dependencies. (I know I tried before to convince pylint to do that, with extremely limited success.)

In lieu of that, the only other solution I can think of is to improve this plugin's multi-project support, e.g.:

  • Automate installing mypy into every project's virtualenv
  • Run mypy for each project in turn and collect results
  • Per-project configuration instead of just "for current project"

I know literally nothing about IntelliJ plugin development, but if others are interested in improving multi-project support, I could create a feature request ticket with my UI/UX ideas.

derula avatar Apr 26 '23 14:04 derula