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

Output issue with c-c c-c in OSX emacs 25 #1307

Closed
tlxu opened this issue Mar 3, 2018 · 11 comments
Closed

Output issue with c-c c-c in OSX emacs 25 #1307

tlxu opened this issue Mar 3, 2018 · 11 comments

Comments

@tlxu
Copy link

tlxu commented Mar 3, 2018

print("Hello world.")
...: print("Hello world.")
import codecs, os, ast;__pyfile = codecs.open('''/var/folders/1w/1_qh215x5w96k1d_q8pmhdph0000gn/T/py1085C0T''',
encoding='''utf-8''');__code =
__pyfile.read().encode('''utf-8''');__pyfile.close();os.remove('''/var/folders/1w/1_qh215x5w96k1d_q8pmhdph0000gn/T/py1085C0T
''');__block = ast.parse(__code, '''/Users/fos/tmp/hell.py''', mode='exec');__last = __block.body[-1];__isexpr =
isinstance(__last,ast.Expr);__block.body.pop() if __isexpr else None;exec(compile(__block, '''/Users/fos/tmp/hell.py''',
mode='exec'));eval(compile(ast.Expression(__last.value), '''/Users/fos/tmp/hell.py''', mode='eval')) if __isexpr else None
<_ast.Expr object at 0x10464a2e8>
Hello world.
Hello world.

Note:
If there is only one single line of source code, say:
print("Hello world.")

the output is clean:

print("Hello world.")
print("Hello world.")
Hello world.

As long as we have more than one line source code, we'll get something like:

print("Hello world.")
...: a=3
import codecs, os, ast;__pyfile = codecs.open('''/var/folders/1w/1_qh215x5w96k1d_q8pmhdph0000gn/T/py1085Dny''',
encoding='''utf-8''');__code =
__pyfile.read().encode('''utf-8''');__pyfile.close();os.remove('''/var/folders/1w/1_qh215x5w96k1d_q8pmhdph0000gn/T/py1085Dny
''');__block = ast.parse(__code, '''/Users/fos/tmp/hell.py''', mode='exec');__last = __block.body[-1];__isexpr =
isinstance(__last,ast.Expr);__block.body.pop() if __isexpr else None;exec(compile(__block, '''/Users/fos/tmp/hell.py''',
mode='exec'));eval(compile(ast.Expression(__last.value), '''/Users/fos/tmp/hell.py''', mode='eval')) if __isexpr else None
Hello world.

Even though it yields the output correctly at the end of the buffer, but the output is really annoying.

My env:
Python: 3.6.4
Emacs: 25.3.1
OSX: Darwin Kernel Version 17.4.0

@jorgenschaefer
Copy link
Owner

That looks pretty weird, what's the output of M-x elpy-config?

@tlxu
Copy link
Author

tlxu commented Mar 7, 2018

Thanks for following up Jorgen. Here is output of elpy-config in my Emacs:

Elpy Configuration

Virtualenv........: None
RPC Python........: 3.6.4 (/usr/local/bin/python3)
Interactive Python: /usr/local/bin/python3 (/usr/local/bin/python3)
Emacs.............: 25.3.1
Elpy..............: 1.18.0
Jedi..............: 0.11.1
Rope..............: Not found (0.10.7 available)
Autopep8..........: Not found (1.3.4 available)
Yapf..............: Not found (0.20.2 available)
Syntax checker....: flake8 (/Library/Frameworks/Python.framework/Versions/3.6/bin/flake8)

You have not activated a virtual env. While Elpy supports this, it is
often a good idea to work inside a virtual env. You can use M-x
pyvenv-activate or M-x pyvenv-workon to activate a virtual env.

The directory ~/.local/bin/ is not in your PATH. As there is no active
virtualenv, installing Python packages locally will place executables
in that directory, so Emacs won't find them. If you are missing some
commands, do add this directory to your PATH.

The autopep8 package is not available. Commands using this will not
work.

[run] /usr/local/bin/python3 -m pip install --user autopep8

The yapf package is not available. Commands using this will not work.

[run] /usr/local/bin/python3 -m pip install --user yapf

Options

Square brackets indicate buttons; type RET or click mouse-1 on a
button to invoke its action. Invoke [+] to expand a group, and [-] to
collapse an expanded group. Invoke the [Group], [Face], and [Option]
buttons below to edit that item in another window.

[+]-- [Group] Elpy
[+]-- [Group] Python
[+]-- [Group] Virtual Environments (Pyvenv)
[+]-- [Group] Completion (Company)
[+]-- [Group] Call Signatures (ElDoc)
[+]-- [Group] Inline Errors (Flymake)
[+]-- [Group] Snippets (YASnippet)
[+]-- [Group] Directory Grep (rgrep)
[+]-- [Group] Search as You Type (ido)
[ ]-- [Group] Django Extension

@jorgenschaefer
Copy link
Owner

I have no idea why that would happen. It seems that Emacs' python.el does not recognize the prompt or output of the subprocess correctly. Does the same happen without Elpy and using M-x python-shell-send-buffer?

@jorgenschaefer jorgenschaefer modified the milestones: v1.19, v1.20 Mar 31, 2018
@mbruggs
Copy link

mbruggs commented Apr 19, 2018

I've had the same issue and came across a discussion about it in the emacs bug system. A local fix is proposed at
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25753#71

On my system:
osx 10.13.4
python 3.6.5 'official'
emacs 25.3

I had to do
$ easy_install-3.6 gnureadline
$ cd /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload
$ mv readline.cpython-36m-darwin.so readline.cpython-36m-darwin.so.bak

It seems to be working ok now.

@vv111y
Copy link

vv111y commented May 4, 2018

I would like to jump in here. @mbruggs solution above works except that this stuff is not removed from the command history of the repl, ie entering history. I want to find a way to remove this; after experimenting the goal is to capture the session inputs as future code.

@rgemulla
Copy link
Collaborator

Do you also see this error when elpy-shell-echo-input is set to nil? If not, then a solution may be to fix elpy-shell--python-shell-send-string-echo-advice (although its actually seems to capture the code piece mentioned above already).

@vv111y
Copy link

vv111y commented Aug 17, 2018

@rgemulla
Getting back to this...

setting elpy-shell-echo-input to nil did not change the situation.
Also, the problem has returned. I'll retry the fix, and there is also another option in comments here

@rgemulla
Copy link
Collaborator

Yes, the problem seems to be in Emacs, not in elpy.

@galaunay
Copy link
Collaborator

galaunay commented Jul 6, 2019

I am closing this, as it seems to be an upstream issue.
Please re-open if not.

@galaunay galaunay closed this as completed Jul 6, 2019
@midas0441
Copy link

midas0441 commented Aug 27, 2020

I am having the same issue. C-c C-c executes fine if the code is a one-liner, but more than that, it gets hung up. My situation is a bit worse than the OP because the execution freezes. I have to KeyboardInterrupt to get back to >>>. The output looks like:

>>> 3+3
... 4+4
... s
import sys, codecs, os, ast;__pyfile = codecs.open('''/var/folders/gk/wcgj14p17x971d5pbrg743ph0000gp/T/pyZD61OD''', encoding='''utf-8''');__code = __pyfile.read().encode('''utf-8''');__pyfile.close();os.remove('''/var/folders/gk/wcgj14p17x971d5pbrg743ph0000gp/T/pyZD61OD''');__block = ast.parse(__code, '''/Users/xxxx/Library/Mobile Documents/com~apple~CloudDocs/aaDocs/code/python/yyyy/yyyy.py''', mode='exec'); __block.body = (__block.body if not isinstance(__block.body[0], ast.If) else __block.body if not isinstance(__block.body[0].test, ast.Name) else __block.body if not __block.body[0].test.id == 'True' else __block.body[0].body) if sys.version_info[0] < 3 else (__block.body if not isinstance(__block.body[0], ast.If) else __block.body if not isinstance(__block.body[0].test, ast.NameConstant) else __block.body if not __block.body[0].test.value is True else __block.body[0].body);__last = __block.body[-1];__isexpr = isinstance(__last,ast.Expr);_ = __block.body.pop() if __isexpr else None;exec(compile(__blo

when I execute:

3+3
4+4
5

My elpy-config is:

Emacs.............: 27.1
Elpy..............: 1.34.0
Virtualenv........: rpc-venv (/Users/xxxx/.emacs.d/elpy/rpc-venv)
Interactive Python: python3 3.7.3 (/Users/xxxx/.emacs.d/elpy/rpc-venv/bin/python3)
RPC virtualenv....: rpc-venv (/Users/xxxx/.emacs.d/elpy/rpc-venv)
 Python...........: python3 3.7.3 (/Users/xxxx/.emacs.d/elpy/rpc-venv/bin/python3)
 Jedi.............: Not found
 Rope.............: Not found
 Autopep8.........: Not found
 Yapf.............: Not found
 Black............: Not found
Syntax checker....: Not found (flake8)

@galaunay
Copy link
Collaborator

Have you tried deactivating shell echoing ((setq elpy-shell-echo-input nil) and/or (setq elpy-shell-echo-output nil)) ?
If one of those fix your issue, it could help us understand what's wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants