On the web, I can find various example on gimp scripting with python.
http://www.jamesh.id.au/software/pygimp/
http://www.gimp.org/docs/python/pygimp.html
We need to import the gimpfu module to get the examples to work. Where can we get the installer of PyGIMP on Windows? It seems the project is dead and the links are broken.
In order to develop Gimp scripts using Python-fu I have followed gimp users article, In short you need to download & install the following:
Python 32-bit from here.
All in one 32-bit from here.
Gimp 2.6 32-bit from here.
Then you need to create your-plugin.py file in C:\Users\MyUsername.gimp-2.6\plug-ins
P.S: Restart your gimp after adding code or modifying your register() function in order to take effect each time.
PyGIMP is part of GIMP (GNU Image Manipulation Program) and can only work in together with it. For Linux distributions it is often found in a different package - but its code lies inside the GIMP code source, and on Windows it is installed alongside GIMP.
As far as I know, the GIMP 2.8 installer for Windows should come with all dependencies (Python interpreter included) for it to work - else all you need to do is to have the dependencies for it to work installed before installing GIMP.
These should be:
Python 2.5, 2.6 or 2.7
Python-gtk
Pycairo
And finally GIMP itself.
Them, you can't just use pygimp as a standalone Python module - it has to be launched from within GIMP to be able to use the program libraries and code. It is relatively easy to create a script that would respond to xmlrpc or similar method, to stay quietly running awaiting requisitions from external scripts to process images with GIMP, tough.
Related
I try to write a simple plugin with gimpfu in python and I tried following those instructions.
1.2. Installation
Gimp-python consists of a Python module written in C and some native python support modules. You can build pygimp with the commands:
./configure
make
make install
This will build and install gimpmodule and its supporting modules, and install the sample plugins in gimp's plugin directory.
Where do I have to execute those commands?
I tried adding my script to the plugins folder but it seems like there is no python module called gimpfu. I believe I have to enable or install it in some way, but I can't find a solutio to do it.
EDIT: It seems like gimpfu is availible in the gimpfy-console insode gimp. It just doesn't seem to be availible for my plugin scripts.
No need to install anything. In the Windows versions Python support is built-in, and the gimpfu import is available when your code is executed by Gimp.
If you don't see the plugin in the menu it is likely a syntax error that doesn't let it run its registration code. See here for some debugging techniques.
However, since you mention PyCharm, you may have another Python interpreter installed and this makes things complicated because there can be conflicts depending on order of installation (and remember, Gimp uses Python 2.7)
Now it all depends if you are really doing a plugin (called from the Gimp menu) or a batch (where Gimp is called from a shell script), which is somewhat different. If you are writing a batch, see this answer for an example.
you don't need to install anything, on windows gimp comes with a python interpreter along with the libraries inside of it.
if you want to run your script from inside GIMP then you should check this answer and you should add the path to gimp to your system PATH environment variable (which is C:\Program Files\GIMP 2\bin on my system) , and instead of calling gimp-console.exe you should replace that with whatever gimp-console is currently available in that folder, the one on my system is gimp-console-2.10.exe.
I am currently starting a business where I will be providing support to clients directly on their business offices. I need to be able to go to different computers and be able to run custom python scripts, my question is if there's a way to make my python environment portable?
Assuming that your users are running Windows, I see two options here.
If you have already defined which scripts you will be running, compile them into exe files using py2exe, that way you can just plug a USB and run them as needed. (the caveat is that some antivirus will automatically block the unsigned executables)
The other option is to use WinPython, that is a full python environment with a lot of packages already preinstalled that ives in it's own directory. In case you need to install a new package, just use the Powershell or CMD that comes with it and use the preinstalled "pip".
I found something interesting here Portable Python. I use that method to create portable Python 3.9 and 3.10 and everything works so have a look.
I admit at the beginning that I am a novice python developer, so I apologize in advance for questions that may seem stupid.
I prepared python script with GUI (Tkinter), which use plenty external libraries. I'm working on Windows. Currently, I share my program in the form of an .exe file for Windows users, who do not have Python installed on their PCs. Everything works.
Recently I received a query if I can compile my code on an executable file that is usable for Mac users.
I have a number of questions related to this:
1) can I do it from a PC with Windows or i need Mac? I guess I have to have access to a Mac.
2) will my code work on mac without any editing? What about external libraries? Do you know any easy way to copy/paste my "python with used libraries" from Windows to Mac?
3) will I create a executable file in the same way as Windows, I mean I will use a "Pyinstaller" type library?
Thank you in advance for your help.
1) can I do it from a PC with Windows or i need Mac? I guess I have to have access to a Mac.
You can use a virtual machine and build for mac.
2) will my code work on mac without any editing? What about external libraries? Do you know any easy way to copy/paste my "python with used libraries" from Windows to Mac?
Some libraries have different behavior between macOS and Windows, yes. You should consult the documentation for the libraries you are using.
3) will I create a executable file in the same way as Windows, I mean I will use a "Pyinstaller" type library?
If you're actually using pyinstaller then it is compatible with both mac and windows. You have to check that the library you're using is compatible with both by looking at their docs.
An example of this is to use virtualbox mac image.
Install virtualbox (see this)
Install MacOS (see this)
Install the correct python (obviously python.org)
git clone your repository
Setup your virtual environment (or just pip install -r requirements.txt with your requirements file but I'm a stickler about venvs)
Note: I know you said pyinstaller-like but pyinstaller has a note about macos.
Build!
You shouldn't have any trouble. Just make sure the version of python is the same, as I believe the default on mac is 2.7.
Also, python scripts aren't compiled, rather interpreted, so making the file executable doesn't really mean it's a binary file in this case. I'm not sure what method you used to run python on a computer that doesn't have python on it, as there are a few, but if you can manage to do that on windows, it should work on mac.
I have tried portable python but the latest version is 3.2.5. (need 3.6+)
I cannot install libraries on it, even the get-pip.py doesn't work.
I'm trying to figure out how to make my project portable on windows systems that do not have python installed.
Also I want the minimum possible libraries(core python modules) to keep the project as lean as possible,
I would go with cx_Freeze - multiplatform module for freezing your Python script in a way that allows you to open it on other Windows machines even if they do not have Python installed. It got very nice and clear documentation also: http://cx-freeze.readthedocs.io/en/latest/ and works a bit better on Windows machines then alternative PyInstaller from my experience (which has interesting option of one-file-package, but in many cases leads to security warnings due to some dirty hacks used to obtain that feature).
However, it may not be enough if you are using some specific modules in your app, as for example matplotlib, dash, etc modules are very hard to pack correctly with Freezer.
I have found a solution to my own question after a couple of days.
I did not want to create an executable for my project but I wanted a portable python folder so that I can add libraries to it as and when I need.
The recent version of portable python is WinPython.
I had to delete some unnecessary files out of it though.
It's size is about 77 mb after extracting
https://winpython.github.io/
https://sourceforge.net/projects/winpython/files/WinPython_3.6/3.6.5.0/WinPython64-3.6.5.0Zero.exe/download
I have a wxPython application that is almost done & I would like to place it in my portfolio. I have to consider when someone attempts to run my app that they may not have Python, or wxPython, so if they just click the main script/python file its not going to run, right?
How should I distribute my app (how do you distribute ur apps) so that it can be run & also so that it could be run on the 3 major OS's (Unix, Windows, MacOSX)?
I know of py2exe for releasing under windows, but what can I use for Unix & MacOSX to compile the program? Whats the easiest way?
Use Gui2exe and compress with UPX to get unpacked size down.
For a setup file(exe) with uinstall info Inno-Setup is good.
I have use this with wxpython several times and got it to work on all windows versions.
For Gui2exe use optimize(2) - compressed(2) - Bundle files(3)
Bundle files(3) is the most stable,
Bundle files(1) make one big exe-file.
For one exe-file is better as last step to use Inno-Setup
You can use py2exe for Windows and py2app for Mac. PyInstaller works for Windows and Linux. Personally, I use GUI2Exe, which wraps all three and makes them a little easier to use. Note: I don't have a Mac, so I haven't tried it with that. You can check out my series on freezing Python here:
http://www.blog.pythonlibrary.org/2010/08/10/a-pyinstaller-tutorial-build-a-binary-series/
http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/
http://www.blog.pythonlibrary.org/2010/08/31/another-gui2exe-tutorial-build-a-binary-series/
There are a couple others on the blog too.
I suggest both, script for all platforms and frozen binary for lazy windows users.
To answer your latest question, you don't compile python. Python is an interpreted language, it gets compiled on the fly when run. A python frozen binary is actually the python interpreter with your script hardcoded in it. And frozen binaries are windows-only, AFAIK. Besides, Unix and MacOS (usually) come with python pre-installed.