Using ipython as the gimp py-fu interpreter, sending all output and input to the terminal - stdout

Ideally I'd like to be able to start gimp from a terminal, then have that terminal behave as an ipython interpreter for gimp. Someone in this thread on gimp forums (http://gimpforums.com/thread-use-console-as-ipython-gimp-interpreter?pid=20373#pid20373) suggested that I modify my /usr/lib/gimp/2.0/interpreters/pygimp.interp file.
I've taken some guesses, but I have not been successful in tweaking things or finding any documentation on this file.
Assuming that this file could be modified to change which binary gimp uses on activation of the interpreter, what could I do to then send the output and input to stdout and stdin respectively?
Thanks a lot :)

You can simply add this plugin: ~/.gimp-2.8/plug-ins/ipython_console.py,
#!/usr/bin/env python
import gimpfu
import gimp
import IPython
from gimpfu import pdb
gimpfu.register("IPython-Console", "IPython Interpreter",
"Launches IPython interpreter in terminal",
"Nic", "Nicolas CORNETTE", "2014",
"<Image>/Filters/Languages/Python-Fu/_IPython Console",
"", [], [], lambda image,layer: IPython.embed())
gimpfu.main()
Now if I launched Gimp from terminal, I can open Filters -> Python-Fu -> IPython Console, then use IPython from terminal.4
you can also have a look here for an slightly improved version : https://gist.github.com/ncornette/8b799c0345eaba56cc8c
Avoid pressing Ctrl+C in terminal !

Gimp's python-console uses pyconsole module to talk to Gimp Python interpreter.
Try to embed IPython console as described here into python-console.py plugin.
On a 64bit machine, this plugin is located at /usr/lib64/gimp/2.0/plug-ins/python-console.py.

Related

simple program output does not appear anymore in command window after python upgrade

I have been running simple programs with python3.4 without trouble, directly typing the program name (without the .py extension) from a command shell, in the directory where the python scripts are located. The expected output would then appear in the shell, and upon termination of the program the next prompt appears, as expected. I recently upgraded to 3.6.4 to develop more complex applications using NumPy and pandas. since the upgrade however, running the same programs still work (e.g., I can see the tk windows appear and behave as before), but the next prompt immediately appear in the command window while the program is still running, and the expected output from simple print statements is redirected somewhere (where?). On another hand, running the program by typing 'python program_name.py' rather than just 'program_name' works as before, with the output appearing in the command window as expected. what configuration settings could have been present with 3.4.0 and missing with 3.6.4 that would explain those discrepancies? Thank you.

Launching IDE directly from nix-shell

I am new to NixOs and nix-shell and am still getting to know its idioms. Right now I have a Java project which I am using nix-shell via direnv to load up the build tool chain, including a jdk and bazel.
I would like the IDE - in my case ItelliJ - to use this same toolchain. My naive approach is to use a nix-shell script as follows, which is the default.nix in the root of my project, and the one picked up by direnv.
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "my-project";
buildInputs = with pkgs; [
jdk11
bazel
jetbrains.idea-ultimate
];
shellHook = ''
export JAVA_HOME="${pkgs.jdk11}/lib/openjdk"
ln -s ${pkgs.jdk11}/lib/openjdk ./jdk
'';
}
I can then launch IntelliJ with the following command from the shell:
$ idea-ultimate 2>1 > /dev/null &
While it works, I have the following concerns:
Loading up the IDE into my command line shell seems really heavy, especially for the CI build.
It is going to get worse as I add other IDEs the team uses, like Eclipse.
It seems like the wrong way.
I can, of course, install these IDE packages using other Nix facilities, like home manager, which gives me the application launcher in the menu after the right config steps; however, I like directly launching the IDE from the shell to ensure the correct tool chain is in place and in correct paths.
My thought for a next step was to remove the IDE input from this default.nix and create custom nix files which include the inputs for the IDE and a launcher script to actually launch the IDE with nix-shell. My hope is that, if executed from the shell above, it will inherit its inputs, augment it with the IDE input, and then launch the IDE.
Again, my goal is to use nix to launch my IDEs, and use the packages and configs setup by the default.nix which is in the root of the project to ensure consistency.
Suggestions, including alternative approaches, are appreciated.

Spyder not handling relative imports

I am attempting to python3 proof my work and spyder seems to be having an issue with absolute_import.
For demonstration purposes I created two simple files. caller and callme
caller
from __future__ import absolute_import
from .callme import helloWorld
def runme(msg):
helloWorld(msg)
if __name__ == "__main__":
runme('It worked!')
callme
def helloWorld(msg):
print("helloWorld's message is '{}'".format(msg))
if __name__ == "__main__":
helloWorld('Hi')
When attempting to run caller from spyder I get the following error:
ValueError: Attempted relative import in non-package
Running from ipython via the anaconda prompt (python 2) or from jupyter notebook (running python3 or python2) both work properly.
Ideas on how to fix spyder's behavior so it properly recognizes absolute_import?
Spyder versions tried:
3.2.4 Python 2.7.14 64bits, Qt 5.6.2, PyQt5 5.6 on Windows 10
3.3.2 Python 2.7.14 64-bit | Qt 5.6.2 | PyQt5 5.6 | Windows 10
Update
Updating spyder via conda update spyder (now version 3.3.2) did not fix the issue.
If you run python caller.py in a system terminal, you'll get exactly the same error as the one you posted, i.e.
ValueError: Attempted relative import in non-package
So this is not a problem with Spyder (because Spyder runs something similar to python caller.py when you execute a file with Run > Run), but with the way relative imports works.
Please see this answer for a proper explanation:
https://stackoverflow.com/a/11537218/438386
In essence, you can't use relative imports in scripts.
Note: There's a workaround to avoid this error, as described in this answer:
https://stackoverflow.com/a/11536794/438386
However, we don't have the ability to execute a script as a package in Spyder, sorry.

Downloaded module not found in IDLE

I am trying to use some libraries I downloaded, but whenever I check for them in IDLE I don't see them.
The same thing happens when I type from sklearn import datasets
But when I try to pip install I see this:
Does this mean I am limited to only the Spyder IDE?
There are somehow distinct distributions of Python that you seem to be running. I would suggest using virtualenv and running your IDE (idle/others) via that. Here's a tutorial video for it. [1]
[1] https://teamtreehouse.com/library/idle-in-a-virtual-environment-2

How to batch open txt files and save each with Sublime in linux command line?

How to command Sublime from linux command line?
I know how to open file in background but not how to call save function?
I have some character issues which Sublime seems to fix and therefore I'd like to run a batch of files through Sublime.
So the available commands are listed on the reference section of docs:
https://docs.sublimetext.io/reference/commands.html

Resources