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.
Related
When implementing a Visual Studio extension to be used with Python files in the VSCode editor, how can one programmatically get the path of currently selected Python environment?
My guess is that it is done with python.pythonPath, but I can't seem to make it work. If I use that directly within an extension js, it crashes. I also tried:
let python = vscode.extensions.getExtension('python');
python.pythonPath
python.pythonPath is a setting, so you can do this with VSCode's generic settings API (instead of having to rely on the Python extension exposing an API specifically for this):
vscode.workspace.getConfiguration("python").get("pythonPath")
I want to write IDAPython scripts and plugins. The problem is to get my Python IDE (PyCharm) to resolve the imports correctly and therefore get code completion correct.
Here is an example. I want that code completion works for IDAPython commands like:
ea = ScreenEA()
or
ea = idc.get_screen_ea()
Here is what I did. I downloaded IDAPython and put the source in my Python projects source folder.
I also copied the python folder from the IDA install directory into my Python projects source directory.
It turns out, that Pycharm cannot resolve the functions correctly.
How to setup Python IDE make auto complete work?
As long as the IDAPython files show up in you Pycharm project, or are in the same folder, you simply need to import the file you want to use.
So for your idc.get_screen_ea() example, as long as you have this at the top of your python file you are working on:
#import idc
Then you will get suggestions for anything involving idc.
Here is the method I took for PyCharm Windows version. First create an venv based project with the python version match your IDA python version.
File -> Settings -> Project -> Python Interpreter
Click setting icon, select Show All...
Select the interpreter you currently use, click Show paths for the selected interpreter
At the popup window, add your %IDA_INSTALL_PATH%\python
Then you can use PyCharm IDE features to write IDA python plugin.
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
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).
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?