15

I dont know why; but since python 3.8 has been released; I cant run pycharm console and it is always in the "being connected" status.

I have had no problem with python 3.7; since the console is opened immediately.

Here you can see that I have tried several times to run the console but I know, even if I wait a day; It does not connect to console; but when I change the interpreter from python3.8 to python3.7, The new consoles I open are all set up within a second.

The Error:

C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\_pydevd_bundle\pydevd_resolver.py:138: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if found.get(name) is not 1:
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\pydevconsole.py", line 33, in <module>
    from _pydev_bundle.pydev_console_utils import BaseInterpreterInterface
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\_pydev_bundle\pydev_console_utils.py", line 11, in <module>
    from _pydevd_bundle import pydevd_thrift
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\_pydevd_bundle\pydevd_thrift.py", line 17, in <module>
    from pydev_console.protocol import DebugValue, GetArrayResponse, ArrayData, ArrayHeaders, ColHeader, RowHeader, \
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\pydev_console\protocol.py", line 6, in <module>
    _console_thrift = _shaded_thriftpy.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), "console.thrift"),
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\parser\__init__.py", line 29, in load
    thrift = parse(path, module_name, include_dirs=include_dirs,
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\parser\parser.py", line 502, in parse
    parser.parse(data)
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_ply\yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_ply\yacc.py", line 1106, in parseopt_notrack
    p.callable(pslice)
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\parser\parser.py", line 212, in p_struct
    val = _fill_in_struct(p[1], p[3])
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\parser\parser.py", line 765, in _fill_in_struct
    gen_init(cls, thrift_spec, default_spec)
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\thrift.py", line 103, in gen_init
    cls.__init__ = init_func_generator(default_spec)
  File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\_compat.py", line 102, in init_func_generator
    new_code = types.CodeType(len(varnames),
TypeError: an integer is required (got type bytes)

The Photo:

The screen shot

pycharm specs: pycharm professional version 2019.1.3

moh80s
  • 695
  • 4
  • 21
  • Did you configer the interpreter? https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html Also, which python (if you installed both) is in your path? – Swedgin Dec 17 '19 at 10:22
  • @Swedgin; Yes I did, the configuration and the path was correctly given to the pycharm. – moh80s Dec 17 '19 at 10:24
  • @Swedgin, have you any guess on what the error is saying to us ? – moh80s Dec 17 '19 at 10:26
  • Sorry, can't help you. Been a long while since I used pycharm. Those were the only 2 problems I could think of. – Swedgin Dec 17 '19 at 10:44

1 Answers1

12

It works fine on PyCharm (Community) 2019.3.

PyCharm ships [PyPI]: thriftpy (for current version, it's a modified v0.3.8), as it needs it for different features (including the Python Console).

Python 3.8 came with a set of changes (one example is [Python]: PEP 570 -- Python Positional-Only Parameters) requiring changes in many of the existing (3rd-party) packages in order for them to work (for some of them, there's still WiP).

Apparently, ThriftPy is one of those packages that require changes. However it hasn't been maintained since 2016, so JetBrains keeps (a copy / fork ?) in their repository.

Anyway, the problem you're facing, was fixed by [GitHub]: JetBrains/intellij-community - PY-36069 Python console support for Python 3.8.
Unfortunately, I couldn't find the issue on JetBrains.YouTrack, so I don't have any additional info about it (like when it was fixed, and so on).

What I can tell you (also mentioned at the beginning), is that it was fixed (works) in PyCharm (Community) 2019.3, so if you upgrade it, you should no longer have this problem.

A workaround (if upgrading is not an option) would be to apply the patch (in the commit URL) to your (local) _compat.py file. Check [SO]: Run / Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (@CristiFati's answer) (Patching utrunner section) for how to apply patches (on Win).
Small mention: applying the reversed patch to my local file, made the problem visible.

CristiFati
  • 28,721
  • 9
  • 41
  • 63
  • That's great, thank you! Actually, I thought that Pycharm have probably fixed this so I updated Pycharm before setting the bounty, and it didn't solve the problem. Apparently, the update was from 1.3 to 1.4, even though version 3 was already available. Updating again solved the problem as you said. – Ella Sharakanski Jan 07 '20 at 21:00
  • @EllaSharakanski, thanks for the bounty and also thanks `@CristiFati` for the response. – moh80s Jan 09 '20 at 10:07
  • I also have this constant issue `Connecting to console`, and I cannot use the answer's solution as I need to run PyCharm 2018.3 because that is the last version supporting 32 bit. I am using normal Python interpreter. I can run Python scripts using "Run" from the menu, but if I right-click selected lines and choose "Execute Selection in Console" (or Alt+Shift+E), there is no execution. I added a comment to get it solved for PyCharm 2018.3 as well on https://github.com/JetBrains/intellij-community/commit/07ef928f3b1fbc24401380110691342a558de242 – questionto42 Jun 28 '20 at 12:09
  • 1
    @Lorenz: You could apply the changes to your local installation, as I instructed at the end of my answer. – CristiFati Jun 28 '20 at 17:56
  • I found that *_combat.py* in "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.7\helpers\third_party\thriftpy\_shaded_thriftpy\". I copied it to "C:\tmp\", then changed the code from red to green as in your commit URL https://github.com/JetBrains/intellij-community/commit/07ef928f3b1fbc24401380110691342a558de242. Then I renamed the ending from .py to .patch. Then I followed your link, **Patching utrunner** section, now applying it to "_combat.py" instead. I used http://gnuwin32.sourceforge.net/packages/patch.htm as the patch.exe instead of Cygwin patch pkg. – questionto42 Jun 29 '20 at 14:37
  • Now, the patch.exe does not accept the patch file: In cmd prompt, I first go to folder `C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.7\helpers\third_party\thriftpy\_shaded_thriftpy`, I execute patch.exe with `"C:\Program Files\GnuWin32\bin\patch.exe" -i "C:\tmp\_compat.patch"` which gives me: `patch unexpectedly ends in middle of line C:\Program Files\GnuWin32\bin\patch.exe: **** Only garbage was found in the patch input.` – questionto42 Jun 29 '20 at 14:40
  • Just save https://raw.githubusercontent.com/JetBrains/intellij-community/07ef928f3b1fbc24401380110691342a558de242/python/helpers/third_party/thriftpy/_shaded_thriftpy/_compat.py locally and overwrite your version (don't forget to backup it first). – CristiFati Jun 29 '20 at 14:54