I decided to use NppExec to run my Python files from notepad++, however I encountered a problem. I created a simple script with one line:
python -i $(FULL_CURRENT_PATH)
and added the script to the "Menu items" in nppExec advanced options. The script appears in my macros tab and does what I need when I run it. The problem is I am unable to set a keyboard shortcut to this command. The command appears in my shortcut mapper (under plugin commands) and I can set it to
shift+ctrl+p
but the problem is that it simply does not work when I hit the three keys. The key combination is not the problem, as I was able to create a test macro that ran when I hit shift+ctrl+p.
Edit:
More updates: the shortcuts.xml in APPDATA does change when I add the shortcut, the line:
<PluginCommand moduleName="NppExec.dll" internalID="20" Ctrl="yes" Alt="no" Shift="yes" Key="80" />
is added. This is exactly my ctrl+shift+p command, it's there, it just does not fire.
Is anyone else experiencing this strange behaviour?
Any help will be greatly appretiated.
Ctrl+Shift+P is by default assigned to Playback command. Notepad++ is buggy when it comes to shortcut mapping, can easily create collisions. See for example open bug #3635.
My suggestion is to try to assign it to something else (personal preference is F5) and double check that it's not already assigned!
Related
I just made the transition from Spyder to VScode for my python endeavours. Is there a way to run individual lines of code? That's how I used to do my on-the-spot debugging, but I can't find an option for it in VScode and really don't want to keep setting and removing breakpoints.
Thanks.
If you highlight some code, you can right-click or run the command, Run Selection/Line in Python Terminal.
We are also planning on implementing Ctrl-Enter to do the same thing and looking at Ctr-Enter executing the current line.
You can:
open a terminal at Terminal>New Terminal
Highlight the code you want to run
Hit Terminal>Run Selected Text
As for R you can hit CTRL Enter to execute the highlighted code. For python there's apparently no default shortcut (see below), but I am quite sure you can add yours.
In my ver of VSCode (1.25), shift+enter will run selection. Note that you will want to have your integrated terminal running python.
One way you can do it is through the Integrated Terminal. Here is the guide to open/use it: https://code.visualstudio.com/docs/editor/integrated-terminal
After that, type python3 or python since it is depending on what version you are using. Then, copy and paste the fraction of code you want to run into the terminal. It now has the same functionality as the console in Spyder. Hope this helps.
I'm still trying to figure out how to make vscode do what I need (interactive python plots), but I can offer a more complete answer to the question at hand than what has been given so far:
1- Evaluate current selection in debug terminal is an option that is not enabled by default, so you may want to bind the 'editor.debug.action.selectionToRepl' action to whatever keyboard shortcut you choose (I'm using F9). As of today, there still appears to be no option to evaluate current line while debugging, only current selection.
2- Evaluate current line or selection in python terminal is enabled by default, but I'm on Windows where this isn't doing what I would expect - it evaluates in a new runtime, which does no good if you're trying to debug an existing runtime. So I can't say much about how useful this option is, or even if it is necessary since anytime you'd want to evaluate line-by-line, you'll be in debug mode anyway and sending to debug console as in 1 above. The Windows issue might have something to do with the settings.json entry
"terminal.integrated.inheritEnv": true,
not having an affect in Windows as of yet, per vscode documentation.
I'm new to python and pycharm and I'd like to run a module from the pycharm console in the same way as you can from IDLE, if it's possible.
The idea is to create simple functions and test them "live" using the console.
...how do you do that in pycharm?
Running python scripts using pycharm is pretty straightforward, quote from docs:
To run a script with a temporary run/debug configuration Open the
desired script in the editor, or select it in the Project tool window.
Choose Run on the context menu, or press Ctrl+Shift+F10. So
doing, a temporary run/debug configuration is created on-the-fly.
Besides there is a "Python Console" available in pycharm: see documentation.
UPD:
Here's an example.
Imagine you have a python module called test_module.py:
def a(*args, **kwargs):
print "I'm function a"
def b(*args, **kwargs):
print "I'm function b"
Then, in pycharm's "Python Console" you can do this:
>>> from test_module import *
>>> a()
I'm function a
>>> b()
I'm function b
If you need to execute a part of an existing code, you can use the Execute Selection in Console feature: select the code snippet -> right click -> "Execute Selection in Console".
For anyone still having this problem: Go to the Run/Debug menu, choose Edit Configuration, check the box 'Show command line' this will enable you to enter parameters in the console at the >>> prompt and test your function.
Edit: To make this change apply to all your .py files (as this check box only applies to the current file you're working on) go to: Edit configuration, in the pop up you will see a menu tree on the left, select Defaults, then Python, then check the 'Show command line' box, this will make it the default setting whenever you open a .py file, (this feature should really be on by default!)
Right Click --> Run File In Console
Done!
Looks like in version 2018.3, this option is now Run with Python console in Run/Debug Configurations:
What you're looking for is the feature called Execute Selection in Console which is described in section Loading Code from Editor Into Console of PyCharm's online help.
Select the script lines that you want to execute and press Shift+Alt+E
You can run the Find Action shortcut (Ctrl+Shift+A or ⌘+⇧+A on mac), then type run file, and choose the option Run file in Console.
In pycharm do:
Run>Edit Configuration>Show command line afterwards
Assuming your code is in file MySimpleCode.py you can simply say
run MySimpleCode
in the PyCharm console. This assumes that you have set your working directory properly; e.g. if MySimpleCode.py is located in d:\work on a Windows system you must execute
cd d:\work
first. In my opinion the other solutions miss what the post really wants: simply executing a file like from a DOS or Unix shell, or a .m script in MATLAB. No messing with imports, projects and so on. If you use CTRL SHIFT F10 your code gets executed, sure, but in a different environment, so you have no access to variables created in your code. I assume the question means that you want to do further work with the results of the script.
Explanation for people with MATLAB background: In most Python IDEs you have to configure an interpreter first in some kind of project. The MATLAB equivalent would be a master IDE where you can choose your MATLAB version for each project. This makes it possible to run your Python code on the CPU, your GPU or even an external NVIDIA board with different settings (after several days in the installation hell). For the beginner this is very confusing, because for simple code samples any "default" interpreter should suffice. Unfortunately this is not the case for Python (2 or 3? 2.x or 2.y? which package version?), and it will get worse as you progress (which 32 or 64 bit version of TensorFlow is available for Python 3.x? and so on).
Under the Build menu, I can see 'Execute' option, but it is greyed out.
The only option available is 'Set Includes and Arguments'. When I click that both fields are already filled out. What do I have to write there?
I don't need to configure anything in Geany. I just hit F5 and the current module is executed.
Are you sure that your file is recognized as a Python source file? Which version of Geany are you using (I am using the SVN version, which is pretty stable; damn, it's rock solid stable ;-))? I have a slightly more developed configuration for Python compilation in my version, but the commands are the same and it works very well.
I had the same problem and found the following solution:
In the 'Build Options' dialogue, click on '_Execute' at the bottom of the dialogue and the _execute options become editable.
I put the full path name to my Python install in there (C:\Python27\python %F) or (C:\Python32\python %F) and it seems to work just fine.
For some unknown reason a new installed Geany at Ubuntu 19.04 (Disco Dingo) had python "%f" at Build → Set Build Commands → Execute default settings.
I solved a similar issue with python3 "%f" instead.
Also don’t forget to set the “KeyBinding”, i.e., the keyboard shortcut-key (single or combination) you press to activate “Run, Execute, Compile, Save, Find, Print, etc...
To do so;
Menu Edit → Preferences → Keyboard Shortcuts.
Here you can choose/change any Key/s to map to any action you want.
Why? Because some other Linux program might have been overridden, or might have taken the default Geany assigned map keys.
You need to set the path variables in the beginning. Or you need to set the variables in Build → set build commands.
This video can give you good clarity:
Install Geany for Python
Your compile path is looking fine. But in the execution path, give the full path of your python.exe. In my case it is...
C:\python27\python "%f"
Find the Python console path.
Now set the environment variable
We all know that windows has the feature that you can right click on a file and numerous options are shown. Well you can add a value to this menu. I followed this guide : jfitz.com/tips/rclick_custom.html
Basically I have a script that runs when I right click on a certain file type.
Alright, so everything is going flawlessly, however when I finish and try to test it out Windows tells me that it only accepts .exe's.
Is their a way around this without having to use py2exe or something similar?
**EDIT
Ok , so if my script takes the first argument as it's parameter how would I put this into the registry?
"C:\Python26\pythonw.exe C:\Users\daved\Documents\Python\backup.py "%1""
?
yes, call pythonw.exe and pass the script path as a parameter
"C:\Python26\pythonw.exe" "C:\Users\daved\Documents\Python\backup.py" "%1"
It's also recommended (but not required) to use the extension .pyw when your script doesn't run in a console.
I'm debugging my Python code in Eclipse using the Pydev plugin. I'm able to open a Pydev console and it gives me two options: "Console for currently active editor" and "Python console". However none of them is useful to inspect current variable status after a breakpoint.
For example, the code stopped at a breakpoint and I want to inspect an "action" variable using the console. However my variables are not available. How can I do things like "dir(action)", etc? (even if it is not using a console).
This feature is documented here:
http://pydev.org/manual_adv_debug_console.html
The console that opens in the debug perspective is in fact interactive, although it took me a while to realize it. You need to hit return twice after typing something and then it gets evaluated.
More info on the Pydev site here: http://pydev.org/manual_adv_debug_console.html
Double click on "action" or any other variable.
ctrl+shift+D
And if you're using watches, I cant imagine better interaction. You are able to see every change.
When I set a break point and hit F11 Eclipse launches the debugger and prompts to open the "Debug Perspective". You can then open the Window-->Show View --> Expressions which opens the expressions view, you can then right click in the Expressions view windows and choose "Add Watch Expression" to add any expression(such as dir)
Conversely I was also able to type in dir(some expression) in the PyDev console and get the same effect.
I'm using PyDev 1.4.6.2788
On a small monitor, you may not realize that the debug interactive console is different from the regular interactive console: it has a second command prompt at the bottom where you type, not at the top like the normal console.