Show run & debug toolbar in PyCharm - python

How do I get this run & debug toolbar to show in PyCharm? It shows in some of my projects, but not others.
And, in the spirit of teaching a man to fish, is there an easy way to find this using PyCharm's own help facility?

As #lukassz commented above, if you want to have the run/debug toolbar, you have to edit your run/debug configuration:
The manual way:
Go to Run > Edit Configuration > Hit the + sign on the top left of the subsequent window > Create a new run configuration.
The semi-automatic way:
With the file that you want to run, open on your editor, hit Shift + Alt + F10 (if you are using the default keymap) or Run > Run/Debug .
On the subsequent pop-up window, choose the file to run and PyCharm will (try to) run it for you.
In the process, a configuration will be generated, which persists.
The fishing lesson: Here is a pond with fish and the tools to catch the fish in question.
Happy fishing and good luck :D

I was able to show the 'Run Configurations' toolbar by selecting View / Appearance / Toolbar.
If you right-click on the Toolbar, you can access 'Customize Menus and Toolbars' for further customisation.
More information on customizing Pycharm toolbars

Related

How to change PyCharm keyboard shortcuts on Mac

I want to change the run console command to pressing SHIFT and ENTER. I followed this tutorial but am unable to understand the actual step to input my personal commands.
I've made it all the way to the screenshot below and need more specific directions to input my personal commands. What do I do next?
That tutorial is about controlling/setting config for a specific run/script. To change keyboard shortcut/settings go your PyCharm preferences. Select Keymap on the left and in the search bar type "Run". You should see it under Run as the first option. Right click on it and you should see an "Add Keyboar Shortcut" and enter your preferred keyboard shortcut.
Keep in mind that Shift + Enter is already assigned so either change that or try another combination

Why is the green run button grey/disabled? Pycharm [duplicate]

I observed that on a new project the Run option is disabled and I expected to be able to run a script without having to manually add a configuration for it.
If you're creating a project from existing source:
and
If the existing source directory contains a lot of data/files:
the Run option (and others, assumably) are disabled until PyCharm is finished indexing the contents in the project. You'll see a progress bar in the lower-right-hand corner.
You can speed this up by right-clicking on folders and selecting "Mark directory as..." -> "Excluded" if they aren't to be indexed.
Right click inside your main file & then you get Run option!
You can't run without a configuration, however temporary configuration can be created automatically if you use Run context menu option in the script editor.
I solved it just by right clicking on the .py file and clicking 'run'. After this the run button appeared enabled!
If the project folder contains a lot of files then the indexing process can take a long time. So you might need to wait before the Run button appears.
Select drop down menu to the left of the run button at the top right, select Edit configurations, expand defaults on the left, select whatever you were working on (if python, select python). Then click OK. Dialogue will close. Make sure the file that you want to run is on top. Hit ctrl+shift+F10 to run. The run button should be enabled again.
Select your file name in drop down menu on top right corner.
Then go to edit configurations.
Next the Run/Debug Configurations dialog box will be open.
Then under execution, uncheck Run with Python console
Apply> Ok
Then you will get the Run window again.
It is possible that when you have newly setup your pycharm environment, it starts to index the scripts. You will see something like Indexing... at the bottom of the window. Once it is complete you can right click and select Run.
I tried all answers, and none worked for me. What did work is:
1.) open another repository / project
File > Open > select project > OK
2.) If you have the pop-up to choose "This Window or "New Window", chose "This Window"
3.) Open the repository / project that had the greyed out run button
4.) It should be green by now

How do I make pyCharm stop hiding (unfold) my Python imports?

Every time I open a Python file PyCharm will hide all imports and shows:
import ...
within the editor.
I have to manually unfold it to see the imports. Where do I find the setting to undo auto-hiding of import statements?
As this question may be useful for people who also are not looking for the term "code folding", I'll make my comment an answer.
As extracted from IntelliJ IDE Web Help, but also worked on PyCharm CE 3.4.1:
Open the IDE Settings (File > Settings, or Ctrl+Alt+S).
Under the "Editor" node, click "General" and then "Code Folding". The "Code Folding" page is displayed.
In the "Collapse by default list", select the check boxes to the left of the code constructs you want to be displayed collapsed. So here you can uncheck "Imports".
Apply changes.
The image below shows what it looks like:
Actually in pycharm 2016.1 it's Editor -> General -> Code Folding

osx open Proxies tab in network preferences programmatically

How can I programmatically open the 'Proxies' tab in 'Network' dialog box?
System Preferences > Network > Advanced > Proxies
For those using Chrome, if you go to Menu > Settings > Show Advanced Settings > Change proxy settings... , the 'Network' box shows up, and its already on the 'Proxies' tab.
I want to achieve this using python.
The way to do this is through Apple Events. If you open AppleScript Editor, you can Open Dictionary on System Preferences and see the commands:
tell application "System Preferences"
reveal pane "com.apple.preference.network"
end tell
So, how do you do this from Python? There are three options:
Create some AppleScript and run it via PyObjC, or via a wrapper like py-applescript.
Use ScriptingBridge, Apple's AppleEvents-to-Python (and -Ruby and -ObjC) bridge.
Use appscript, a third-party AppleEvents-to-Python (and …) bridge.
Appscript is a lot better, but it's effectively an abandoned project, and ScriptingBridge comes with Apple's version of Python. So, I'll show that first:
import ScriptingBridge
sp = ScriptingBridge.SBApplication.applicationWithBundleIdentifier_('com.apple.SystemPreferences')
panes = sp.panes()
pane = panes.objectWithName_('com.apple.preference.network')
anchors = pane.anchors()
dummy_anchor = anchors.objectAtIndex_(0)
dummy_anchor.reveal()
You may notice that the ScriptingBridge version is a lot more verbose and annoying than the AppleScript. There are a few reasons for this.
ScriptingBridge isn't really an AppleEvent-Python bridge, it's an AppleEvent-ObjC bridge wrapped up in PyObjC, so you have to use horribleObjectiveCSyntax_withUnderscores_forEachParameterNamed_.
It's inherently horribly verbose.
The "obsolete" method of looking applications up by name isn't exposed in ScriptingBridge, so you have to find the bundle ID (or file:// URL) of the app and open that.
Most importantly, ScriptingBridge doesn't expose the actual object model; it forces it into a CocoaScripting OO-style model and exposes that. So, while System Preferences knows how to reveal anything, the ScriptingBridge wrapper only knows how to call the reveal method on an anchor object.
While the last two are the most troublesome, the first two can be annoying as well. For example, even using bundle IDs and following the CocoaScripting model, here's what the equivalent looks like in AppleScript:
tell application "com.apple.SystemPreferences"
reveal first anchor of pane "com.apple.preference.network"
end tell
… and in Python with appscript:
import appscript
sp = appscript.app('com.apple.SystemPreferences')
sp.panes['com.apple.preference.network'].anchors[1].reveal()
Meanwhile, in general, I wouldn't recommend any Python programmer move any of their logic into AppleScript, or try to write logic that crosses the boundaries (because I subscribe to the Geneva conventions against torture). So, I immediately start with ScriptingBridge or appscript in any case where we might need so much as an if statement. But in this case, as it turns out, we don't need that. So, using an AppleScript solution might be the best answer. Here's the code with py-applescript, or with nothing but what Apple gives you out of the box:
import applescript
scpt = 'tell app "System Preferences" to reveal pane "com.apple.preference.network"'
applescript.AppleScript(scpt).run()
import Foundation
scpt = 'tell app "System Preferences" to reveal pane "com.apple.preference.network"'
ascpt = Foundation.NSAppleScript.alloc()
ascpt.initWithSource_(scpt)
ascpt.executeAndReturnError_(None)

GEdit/Python execution plugin?

I'm just starting out learning python with GEdit plus various plugins as my IDE.
Visual Studio/F# has a feature which permits the highlighting on a piece of text in the code window which then, on a keypress, gets executed in the F# console.
Is there a similar facility/plugin which would enable this sort of behaviour for GEdit/Python? I do have various execution type plugins (Run In Python,Better Python Console) but they don't give me this particular behaviour - or at least I'm not sure how to configure them to give me this. I find it useful because in learning python, I have some test code I want to execute particular individual lines or small segments of code (rather then a complete file) to try and understand what they are doing (and the copy/paste can get a bit tiresome)
... or perhaps there is a better way to do code exploration?
Many thx
Simon
Yes, you use "external tools plugin"
http://live.gnome.org/Gedit/ToolLauncherPlugin
As an example,
Edit > Preferences
Plugins
Tick "External Tools"
Close the Preferences Window
Tools > Manage External Tools
Click the "Add new too" icon in the bottom left
Name it "Execute Highlighted Python Code"
give it a keyboard shortcut
change the input combo box to : "highlighted selection"
change the output to : "Display in Bottom Pane"
In the editor window for the tool, replace everything with :
.
#!/usr/bin/env python
import sys
result = eval(sys.stdin.read())
print expression, "=>", result, type(result)
.
If you wish to see the result of entire .py file, you can put this code in your new created external tool window
#!/usr/bin/env python
import sys
exec(sys.stdin.read())
and change the Input to Current document.
For python, You can use "external tools plugin":
#!/bin/sh
python3 "$GEDIT_CURRENT_DOCUMENT_PATH"
Option of external tool:
Save: Current Document
Input: Current Document
Output: Display in bottom panel
Language: Python or Python3
Don't forget the quotes around $GEDIT_CURRENT_DOCUMENT_PATH....
To answer your second question, and hopefully guide you in a direction you'll be happier with, I think you ought to consider trying some different editors. There are many with more powerful code exploration features than GEdit has. Check out this post:
What IDE to use for Python?
I installed iPython console in gedit and do most of my simple scripting in it, but gedit is a very simple editor, so it'll not have some advance feature like an IDE
But if you want code exploring, or auto completion, I recommend a real IDE like Eclipse.
If you just want a editor, KomodoEdit is fine.
What I do is keep a file called python_temp.py. I have a shortcut to it in my dock. I use it as a scratch pad. Whenever I want to quickly run some code, I copy the code, click the shortcut in the doc, paste in the text and hit f5 to run. Quick, easy, simple, flexible.
I think what you're looking for is http://live.gnome.org/Gedit/Plugins/BetterPythonConsole.
You hit F5 and it runs the code in your file in a IDLE-like console. I don't know if it can only run selected code. (I don't think it can) but you can always copy the needed code in a new window and run it from there.
Have a look through the plugin list for other interesting stuff: http://live.gnome.org/Gedit/Plugins
The closest to a decent IDE...
Install gedit-developer-plugins (through synaptic || apt-get) and don't forget to enable (what you need) from gEdit's plugins (Edit->Preferences [tab] plugins) and happy coding

Categories