eclipse: Run/Debug current file - python

In search of a Python debugger I stumbled upon Aptana, which is based on eclipse.
Often, I want to debug a single python script. However, Aptana won't let me run/debug the currently opened file directly.
Instead, it requires me to create a debug/run configuration for each file I would like to run/debug. Alternatively I could create a Python project in Aptana.
But: I don't want to. I just want to be able to run or debug the currently opened file. This way I would like to debug my scripts without being forced to create a project first (for each single script!).
Can it be that hard?

This is because Aptana/Eclipse doesn't "realize" that the file you opened should be debugged using the Python debugger as it's not associated with a Python project/perspective (there's a lot of environment setup when a project is created in Aptana/Eclipse).
The simplest solution, IMO, would be to create a simple sandbox Python project and just stick your files in there to run/debug. Aptana should then realize you're dealing with Python and start running the Python debugger without setup (that's my experience w/ PyDev in Eclipse, at any rate).

See: Run External Python Programs with Eclipse PyDev (note: you really need a project, but your file doesn't need to be in it).

Related

What are Django configurations?

I'm setting up a Django project for the first time using Pycharm, and I'm trying to figure out what the configurations do.
I have looked online at the documentation, but it seems to be more focused towards people who already know what configurations do.
I'm assuming it is used to set up my localhost, however I'm unsure. Any help would be greatly appreciated!
In an informal way, we can define PyCharm configurations as a comfortable way to start a new process.
Suppose that you have a Python script called main.py. If you have to run it via command line you will type
python main.py
In the same way, PyCharm offers the possibility to run this script using configuration. It's sufficient create a new Python configuration and setup the script path (location of main.py) and the relative python interpreter.
In fact, can happen that some scripts must be run using a virtualenv or a specific enviroments. For this reason, at the creation of PyCharm configuration we need to specify also python interpreter.
Configurations are not used just to start python scripts, but it's possible to create different types.
As you pointed out in your question, it's possible to create configurations also for Django.
A typical usage in this case is to create a configuration to start the runserver.
But this is not all, because it's possible create configurations also for django commands, for migrations and also for Unit Test.
Pycharm configurations are useful because in this way, no need to setup every time all environment to start a process, but you need just to create configuration and save it. You can use it whenever you want.
Last but not least, using configurations allow you to debug your code easily.
Configurations can be started also in debug mode.
PyCharm documentation
When you run your code/project in PyCharm, maybe you need to specify some set of environment variables, the entrypoint is a particular script in your project, maybe there's some other script you always need to run first before you can run your project, or lots of other fiddly things that are a pain to type in every time.
The purpose of PyCharm "Run Configurations" is to let you save all these kind of things into a single method of running your project with a single click or shortcut.
Django Configurations are a type of Run Configurations with a few extra Django-specific config options thrown in. The default settings in the Run Configuration are sensible (running on localhost:8000), although you will need to make sure you specify the location of your Django Settings File.
How I config Run/Debug Configurations in Pycharm Community:
Add a Python Configuration
Script path: "path to manage.py"
Parameters: runserver "host":"port" "option like '--noreload', '--nothreading'"
Python interpreter: "path to venv"
Now you are able to run with Shift + F10
In order to pycharm general setting left-top File>Setting
screenshot..
enter image description here
Python Setting....
Open a project or import
After open or import you view project name option in rigth-top bar like this
enter image description here
on click you can view configuration option. click it and view this form for all python or other environment setting.
enter image description here

How to configure PyCharm to develop LibreOffice Python macros?

I've installed Python 3.5.1 as default in Win7(x64) for all my projects in Python.
I use PyCharm 5.0.5 community edition for develop Python scripts and its default settings has "Default Project Interpreter" as "3.5.1 (C:\Python35\python.exe)"
At my work we are migrating from MS Office 2007/2010 to LibreOffice-5. I wrote some macros in VBA, despite of I'm not a VB enthusiastic. Basic lacks good data structures, such as lists (I love list comprehensions), dictionaries, sets and tuples. So, I want to rewrite the VBA macros in LibreOffice-5 Python script macros.
LibreOffice-5 installation has its own embebed Python at "C:\Program Files (x86)\LibreOffice 5\program", version 3.3.5. Scripts of Python in LibreOffice-5 installation is at :
Libre Office Macros; "C:\Program Files (x86)\LibreOffice 5\share\Scripts\python"
My Macros; "C:\Users\trimax\AppData\Roaming\LibreOffice\4\user\Scripts\python"
The question is simple:
I need configure PyCharm settings to develop the python scripts of LibreOffice macros with the embebed python version. I don't know if I need to set a virtual environment or if I can just to set the Project Interpreter.
By the way, are there any method to insert macros in the document, to share it with the document, as the VBA Project Modules?
From the PyCharm documentation, it sounds like you could use a virtual environment to target LibreOffice (likely Python 3) and OpenOffice (likely Python 2) in two different projects. Otherwise it looks like a local interpreter is enough.
To test PyCharm, I did the following:
Download PyCharm and create a new project.
It asks which interpreter to use. Click on the gear icon and specify Add Local. Browse to C:\Program Files (x86)\LibreOffice 5\program\python.exe.
Create a new python file.
Then add this code:
import uno
from com.sun.star.awt import Point
p = Point(2,3)
print(p.X)
points = uno.Any("[]com.sun.star.awt.Point", (p,))
print(repr(points))
It underlined the com import statement, although it's not actually an error. PyCharm did recognize the other statements such as uno.Any.
To run, go to Run -> Run. It ran successfully and printed results as expected.
Instead of an IDE, I typically just use a text editor. From what I have seen, a lot of the IDE tools (syntax highlighting, auto completion, debugging) do not work very well with UNO anyway. It is better with Java, but that is a different topic.
By the way, are there any method to insert macros in the document, to share it with the document [...]?
To embed Python code into a document, unzip the .odt file and follow the instructions here.
To embed Python code into a documents, I recommend using the APSO extension. You can download the LibreOffice extension here. It creates a new menu item: Tools...Macros...Organize Python Scripts. From there you can embed or export files.

Configuring a debug environment in Eclipse

I am using Behave to write BDD tests. The problem I have is that I am unable to create debug environment for these tests. I have successfully created an external tool run environment but that is of little help when I want to use breakpoints and debug the code.
Anyone who uses Lettuce/Behave/Freshen/Cucumber and could let me know how is the debug environment setup?
Found a solution on the Eclipse help page : http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-exttools-running.htm
It is possible to debug python steps (*.py) files in Eclipse IDE.
Belove solution works for:
Windows 7
Behave framework from https://pythonhosted.org
Just make:
Copy behave-script.py to directory that are located .feature files. You can find this file in Python27\Scripts\
In Eclipse add new "Debug as...->Debug Configuration->Python Run"
In a project choose your project
In Main module choose behave-script.py
Hit run and set brakepoints
Although you didn't mention Morelia (another BDD tool for Python) I thing you could try it. It doesn't need any special setup to integrate if traditional unittests works for you. Morelia's documentation: https://morelia.readthedocs.org/en/latest/

Auto-Completion for Panda3d in PyCharm

Does auto-completion for the Panda3d library working with PyCharm? It seems PyCharm cannot automatically create the Python skeletons for this library. I would also be happy if I could at least manually define those stubs in PyCharm.
Any ideas how to tell PyCharm what Python modules and classes are there in a "binary" library?
For me it worked just selecting in Settings > Project Interpreter the panda python interpreter (python.exe, not ppython.exe.).
If you wanna use ppython.exe you have to rename to something starting with "python" like pythonpanda.exe, since Pycharm only considers an interpreter something that starts with "python". Anyway, ppython and python are supposed to be the same.
EDIT
Another thing that can make it work, is using another python interpreter (the standard, virtualenv, whatever) and placing a path file in a folder within the PYTHONPATH.
In other words:
Create a text file named panda3d.pth
Write two lines
path\to\pandafolder
path\to\pandafolder\bin
Save it in the site-packages of your python interpreter
Configure Pycharm to use this interpreter

Python programming on Eclipse with Pydev

I need major help getting started! I managed to create a new project, and add python.exe as the interpreter. But when the project is created it's blank. How do I start programming? Ugh.
Create PyDev project
Add "Source Folder" under the project
Add "Modules" to the "Source Folder"
Get coding :-)
Open a new text file and start writing code?
You need to make sure you create a Pydev project. If you don't already have a Python interpreter installed, you'll need to get one (this is mainly a problem on Windows, ActiveState is a great commercial grade distribution, python.org also has some great free builds of Python.) Once this is complete, you'll need to get into your global Pydev preferences (not the preferences for your specific project, but for all Pydev projects) and select the interpreter of your choice. Pydev will automatically scan the libraries included with your interpreter distribution and make them available for code completion. Then, you'll need to create a source file in the 'src' folder that contains code. Run it by choosing a run configuration that matches up with your interpreter choice (regular old Python in your case, not Iron python or Jpython). Most entry point python modules will have a main function like in C/C++ that looks like this: What does if __name__ == "__main__": do?

Categories