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.
Related
I want to distribute a python program on, say, Windows and/or Mac, but I don't want to give the user the headache of ensuring there is an appropriate python runtime installed on their machine. And i don't want to interfere with their machine's configuration by, let's say, requesting root privileges and installing a system-wide python runtime on their system that suits my program specifically because it's too invasive and might cause compatibility collisions with other installed versions of the runtime.
I would much rather have a self-contained executable that could be, for example, stored on a USB flash-drive, inserted into the system, and then maybe with a stepping-stone binary executable that just invokes the device-portable runtime on a python script that I provide, I could then run the program as if it were a self-contained binary executable (with only standard-library dependencies).
A link to this binary executable could be published into main-menu program lists, docks, or desktops. And it could be invoked by shell scripts or other executed-by-proxy mechanisms. Such a no-install/self-contained python program could potentially be a first-class user-invokable application. This is what I want to achieve.
I googled around for projects that provided a device-portable/mobile python installation and so far I've only found portablepython.com. Unfortunately it says the project is discontinued and no download link for the project is provided. it listed some similar projects but they all seemed defunkt or with a very different focus.
Does anyone know of an active project that is or includes such an independent/portable/mobile/no-install distribution for python?
or is there some way i could configure python's build system to build a noinstall-friendly product?
any ideas welcome. thanks for your input!
After more searching I found that Python.org publishes its own standalone-python distribution called the embeddable zip file.
This is exactly what I was searching for. It's a basic python standalone runtime that requires relatively few megabytes of storage.
I started with this embeddable distro and then cajoled a standalone copy of pip to work with it. Problem solved.
Improving upon #oreus2020's answer, you can download the embeddable zip file from here. Then, unzip the compressed file to a folder of your choice. Go to the root of your install and find python._pth file and open it in a text editor. Remove the "#" before import site(This file is the one which manages the environment of the portable install. If you want anything to be recognized by the portable python interpreter, just throw the path in here and that's it!). If you want pip, go to this page and save it in the root of your portable install and run it using the portable python interpreter like ./python get-pip.py from a commandline opened at the root of your install. Pip installed! To use the pip, do ./python -m pip <commands> from the commandline opened at the root of your install and then open the python._pth file and insert the following below the "." ./Lib/site-packages ./Scripts. Voila, you got yourself a python portable install!
My python._pth file looks like:
python39.zip
.
# Uncomment to run site.main() automatically
./Repo
./Repo/Code
./Repo/Code/cogs
./Lib/site-packages
./Scripts
import site
If you are still wondering, here is the link to the one I made for myself.
P.S. Pardon my bad English
I am very new to Python and am trying to learn it so that I can write Mercurial hooks (https://www.mercurial-scm.org/wiki/MercurialApi).
I downloaded PyCharm by Jetbrains with the hope that I could start writing a python script and have the IDE autocomplete for me so I could see what available functions objects have etc. I started with this:
#!/usr/bin/env python
from mercurial import ui, hg
# change . to the path to the repo
repo = hg.repository(ui.ui(), '.')
ui.warn('asdfsadf')
However, as no Python Interpreter is configured, I can't autocomplete (or, at least that's what I think the issue is). I do have Mercurial installed, and when I do pip list I do see the library listed, but PyCharm doesn't know about it. How do I configure thing so that the libraries I want recognized by the IDE get recognized? I know that there are settings which can be set, but I don't understand which ones I want for my purpose.
I found that this post How do I import modules in pycharm? helped me a lot to add the appropriate project interpreter.
I'm new to using python modules.
I'm currently working on a python 2.7 script that will be deployed to many remote computers (which have python 2.7 on them). The problem is that the script needs to use a module, which I am not allowed to install on those computers.
I'm wondering if it is possible to include the module files in the same package as my script (possibly have them compiled first), and then have the script import the library from that local folder, thus achieving a "portable" script.
If that is possible, how would I go about doing that?
Specifics: I'm running 2.7.11 on Windows needing to use Paramiko.
I'm asking this question because the similar questions that I can find either do not answer mine, or expect me to be familiar with core python structures with which I am not. I also DON'T want to include the entirety of python and then install the module onto that, something I see is often called Portable Python. I just want to send my script and the module and nothing more.
Many thanks!
To install modules in a specific directory, you can try pip install module --target=.
By default python search for those modules in same directory as the script first, then, if not available, it will search for python install lib files.
I've made a python script that depends of numpy, cv2 and some other modules to run and need to run it on a Linux server where I'm not allowed to install anything.
Is there a way to join all that stuff into a single executable that runs without installing anything?
It sounds like you're looking for PyInstaller, which bundles all the modules your script depends on into a single program. It even includes Python itself. There are a few alternatives, some of which are listed on this page.
You could create a standalone executable using Nuitka. Assuming you have all required packages on your development machine you can run
nuitka --python-version=2.7 --standalone foobar
Just make sure you run it with the standalone flag and correct python version.
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.