Python shell unresponsive in emacs - python

I'm trying to use emacs as my python develloping environement. But I'm facing a problem.
All communication between emacs and any python interactive shell that is called by python-shell seems broken:
The shell seems to start normally, displaying versions and giving me a prompt but then as I enter commands, nothing seems to happen. I have no answer from the interpreter. I can keep writing things but they then stay there in the middle of the screen and nothing happens. I've tried setting regular python interpreter to python and ipython and nothing changes.
I also try to invoke a system shell, that works correctly, and then call python or ipython from there, that brings me back to the same "no response" situation. It just looks like a normal buffer that I can edit. I can delete through the prompt, write some character anywhere in the screen, in the version info... It doesn't looks interactive at all.
What could be the reason of this problem?

Related

Unable to set up vscode to practice python

Today just for practice I have downloaded and installed vscode.
I saw a tutorial on the installation of vscode for python and followed the procedure exactly.
But upon completion, whenever any python code is running, it is throwing an exception.
Eg:- A simple code I was trying to run like
def greet():
print 'Hello world'
But the terminal is throwing an exception saying "Invalid Syntax"
I really don't know where I am going wrong
If anyone of you has experience working on vscode and is willing to help then please tell me what I can do
The extensions I have enabled:-
Code Runner,
Python
Earlier the python extension was not enabled, but even after enabling it, the error is still there
Please have a look at the problem I am facing in setting things up with vscode
You should not type in python in the terminal.
Because the Python Extension only sends some commands to the terminal and then executes them.
If you type python in the terminal you will enter into the interactive mode, and the commands which intended to be executed in the terminal will be executed in the python interactive mode, and lead to SyntaxError.
So, you can get out of the python interactive mode through Ctrl+Z shortcut or kill the terminal and then execute the commands in a new terminal.

iPython automatically at launch in Visual Studio Code on Os X

I would like that iPython run automatically when I launch VSC instead of typing ipython and press enter in the terminal. The answer here How to set ipython/jupyter as the default python terminal for vscode? doesn't work as it is for windows but it shouldn't be really different. Also, is there something similar to the 'Execute' button in Spyder instead of typing %run filename ? Thanks !
I presume you mean you want to run the "Python Interactive Window" and not just an iPython console on startup
There is currently no way to run it on startup. At least no way without writing another extension that would run a command when opening a workspace. It would be simple for us to add one though. Probably a workspace setting. Can you log an issue here:
https://github.com/Microsoft/vscode-python/issues/new
For you second question, 'Execute' in spyder, we have 'Run Current File in Python Interactive Window'. This works on any python file. You can get to it through the context menu on a file or through the command palette.
Sadly the nice workflow of spyder is not provided by any official extension at the moment (as far as I know).
But you can implement the basics easily on your own by writing an extension. Even with no experience in TypeScript you can quickly build an extension which starts an IPython console as soon as you open a python file. I also managed to execute a startup script which implements the runfile method. VS Code also allows keybindings for your functions, so that you can almost work like you can with spyder.
Spyder modified the IPython terminal quite a bit though, so it won't feel exactly the same. But after all, everything there is open source so you could implement it yourself, which is what I'm trying to do in my free time.

Python in VSCode: How do you run a previous command?

I'm kind of new to software development. Outside of VSCode, I can open up a terminal (let's say PowerShell), run python in it, type in a command (like 2+2), be able to click the up arrow key to find my previous command so that I can run it again.
If I run PowerShell in VSCode and do the same thing, nothing happens when I click the up arrow where I would expect my previous command to be cycled.
Is this a problem with my Python or VSCode? I've been looking for a solution for this but haven't found many useful topics on this.
This was going to just be a comment but its too long. Sorry it isn't more informative than it is. This is kind of an odd problem because VSCode isn't a true IDE. It doesn't have its own shell and just hijacks your powershell or bash terminal, depending on which OS you are using. You should be able to use your up and down arrows just like you can in powershell. I have tested it on my own VSCode installation and it works fine for me. If it's a problem, it's not with python, since VSCode will interact with the terminal the same way no matter which language you are using it for, so its probably with VSCode or your terminal. I have heard of others having issues with up arrow autocomplete in bash, so if you are connecting to a bash terminal that could be it, but I've never heard of it glitching in powershell. I'd say check which terminal you are using, see if the problem persists when you change terminals, and try reinstalling VSCode if it does. Past that, I don't know what to tell you.
I found a work-around. For me, neither git bash, nor PowerShell allowed up/down arrows for history switching within a python shell. So here it goes.
Ctr-Shift-P opens VSCode commands
Python: Create Terminal does not actuallt start python, but it does launch powershell in a mode that will enable us to succeed
py starts python shell with working up/down arrows!

Find the exact .py window/script that corresponds to the IPython console in Spyder

I would like to know if there is way to figure out (from the IPython console) the .py script that was used to run/execute the python commands interactively and thus got printed into the Ipython console.
For eg.
From the below screenshot, looking at the 3+3 in the Ipython console, I can see that it came in when command from untitled2.py was executed.
However when the scripts get long, and IPython output gets long and you are often shifting scripts on the left side, it can be hard to keep track.
So i was wondering if there is a way i can quickly execute some command or view some setting on Ipython console that can tell me that the above line came from untitled.py.
(Spyder maintainer here) There's no way to know from which Editor you're executing some portion of code, sorry.
However, you could use dedicated consoles (under Preferences > Run > Execute in a dedicated console) to have one console per file you execute, as long as you use F5 to run each one of them.
You could edit each .py script, so the first thing it does is to print its name and functionality.
untitled2.py:
print('untitled2.py')
...

What's the difference between coding in the IDLE and the terminal?

I installed python 2.7 and I have the IDLE version of it. I also created two environments using the terminal of Python 3 and Python 2 with conda.
When I type python it shows me that I'm using Python 3.5.2. Now:
How can I switch between two versions in the IDLE or the terminal?
What's the difference between coding in the IDLE or the terminal?
You cannot switch versions of Python from within Python. IDLE runs on top of whatever version of Python, and cannot switch the version running it. You can simultaneously run IDLE 2.7 on Python 2.7 and IDLE 3.5 on Python 3.5.
When you run code from any IDLE editor, it is added your File => Recent files list, which is used for any version of IDLE you run. I frequently pull a file into another running version to see if it runs the same, perhaps after revision for known differences between 2.7 and 3.x.
At least 95% of code that people write runs the same directly in Python (with the -i flag) and IDLE. The IDLE doc, accessible under Help => IDLE Help, notes these differences.
3.2. IDLE-console differences
As much as possible, the result of executing Python code with IDLE is
the same as executing the same code in a console window. However, the
different interface and operation occasionally affects visible
results. For instance, sys.modules starts with more entries.
IDLE also replaces sys.stdin, sys.stdout, and sys.stderr with objects
that get input from and send output to the Shell window. When this
window has the focus, it controls the keyboard and screen. This is
normally transparent, but functions that directly access the keyboard
and screen will not work. If sys is reset with importlib.reload(sys),
IDLE’s changes are lost and things like input, raw_input, and print
will not work correctly.
With IDLE’s Shell, one enters, edits, and recalls complete statements.
Some consoles only work with a single physical line at a time. IDLE
uses exec to run each statement. As a result, 'builtins' is
always defined for each statement.
There are probably a few more equally esoteric things I should add.
IDLE has this feature where it suggests operations on a variable automatically or by using ctrl+space. But in terminal no such suggestion prompts appear in any case.
Not sure how you can switch versions in terminal.

Categories

Resources