I have some python code that runs optimization based on numbers output from fortran code using a simple os.system .out file. Previously I was able to use Spyder to run the python code and in the IPython console only the python print commands would show; this is preferred since the fortran code has lots of print messages that are useless to me but I don't want to go through and comment them out. I switched to a new computer and downloaded Anaconda 4.6.11 and Spyder 3.3.3, and now I can't recreate that situation where only the python code would print.
I've tried changing some settings in the "Run configuration per file" under the Run tab as well as the "Preferences" tab but there's nothing I can find specifically on just outputting the python code to the terminal.
os.system(MachUp.out)
I do remember that the fortran code sent its print messages in a regular terminal while the python code kept its print messages in the IPython terminal. Perhaps it's an older version of Spyder that I should use?
Related
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.
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.
I'm new on StackOverflow, and on VIM, but I really tried to find an answer to my question but found nothing...
I'm on macOS Sierra (latest OS X)
I use MacVim, but the problem is the same if i try on VIM
My backspace works perfectly, every time I need it, in VIM, in bash or in python. Except in that case :
I'm on vim, I try to launch in VIM's console (with :!python) a python program, but when I have to type something, I can't use BackSpace... it writes a ^H (and something as weird as this happens with arrows).
It does the same thing with ipython.
I don't understand how I can make this backspace work specifically in that context ?
In mVIM opened with Conque Term plugin : (But it's the same with :!...)
bash-3.2$ ipython Documents/example1.py
Enter a : 2^H^[[A^[[B^[[C^[[D
Do note that this doesn't happen when :
I launch python or ipython directly in bash (not in VIM)
I launch a program with python or ipython in bash (not in VIM)
I launch python (not a program, only python) or ipython in VIM's bash
I am trying to stop execution of Python scripts in IPython in Windows. I have installed Python and IPython using Anaconda. However, whenever I press Ctrl+C, it breaks out of the current Python script as well as IPython. I saw a similar post here, which said to instead launch IPython with python C:\python27\scripts\ipython-script.py (or wherever that .py script is located), but for Anaconda users that script is in C:\Users\andre\Anaconda3\pkgs\ipython-5.1.0-py35_0\Scripts\ipython-script.py (which then changes with every version number if IPython that is installed). This ends up working but is certainly not convenient. I can make a quick shortcut/keybinding that runs that ipython-script.py script, but if and when I update IPython, I'm going to have to change the shortcut, and that seems rather inconvenient.
Any suggestions? I suppose I could add C:\Users\andre\Anaconda3\pkgs to my path, but that seems a little bit of overkill since there are a ton of packages in there.
I often use R to analyze data, and really enjoy Notepad++ along with NppToR. Especially, NppToR enables to run a part of code without much hassle. I just highlight a snippet of R code to run and press F8. Then the code magically runs in R console.
Now, I am required to use python to analyze data. I know that ipython is great to work interactively, but it is always very annoying to copy a snippet of python code and manually paste that into ipython console. Also, indentation is often mixed and thus the entire lines are failed to run. Note that I want to run 'selected' lines of codes, not the entire file.
So I am looking for a program/plugin/macro similar to NppToR, but working with python/ipython console. I have searched the web, but couldn't find such one. Some plugins are nice, but not exactly what I want. For example, Python Script enables extending Notepad++ itself, but not outside. Various other 'Run' extensions enables the entire file to be run in python.
You can customize the editor IPython uses for the edit command, and configure IPython to use Notepad++. IPython 0.11 creates a .ipython/profile_default folder in your user folder (in my case C:/Users/zk/.ipython/profile_default). To configure IPython to use Notepad++ create .ipython/profile_default/ipython_config.py with the following:
c = get_config()
# use DOS style path, C:/PROGRA~2 on my 64-bit system points to C:/Program Files (x86)
c.TerminalInteractiveShell.editor = 'C:\PROGRA~2\NOTEPA~1\NOTEPA~1.exe'
# set editor for Qt Console, if you wish to use that
c.IPythonWidget.editor = 'C:\PROGRA~2\NOTEPA~1\NOTEPA~1.exe'
You can then start up IPython and use the edit command to run Notepad++ from IPython, saving and closing Notepad++ will execute the file in IPython.
If you don't mind installing PyQt4 and pyzmq (and I believe pygments, at least for IPython 0.12-dev), IPython's Qt console works really well (frankly the nicest interactive environment you can get for Python). You can paste directly into IPython and it'll adjust indentation for you (shifting over padded code).