benwiggy / PDFsuite

Python scripts, Automator Services and Quartz Filters for MacOS (OS X) that create, manipulate, and query PDF files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"ImportError: No module named Quartz" in Mojave

MarjaE2 opened this issue · comments

I'm trying quartzfilter.py, from the Terminal, without success. Getting the above error.

Found instructions elsewhere to run pip install pyobjc-framework-Quartz

... Which said it installed, didn't work, and won't let me uninstall, on the grounds that it's not installed.

Sorry for this. It should work without installing anything. However, it does need improving, so I'll look into it.

Have you installed any other pythons? It's possible that there's a mix-up.

I've tweaked a few things, so see if that is any better.

I'm still getting the above error. Are there any special steps to install Python scripts?

If you're getting an error about the syntax of a particular line, then the script is executing.

Try the latest version. This works for me on both Mountain Lion and Mojave. (Previous versions had problems on the earlier OS.)

Line 13: "from Quartz import PDFDocument"

which python points to usr/local/bin/python, which suggests Homebrew.

OK, in which case you've got another version of python installed, and your shell is not respecting the #! line at the top of the script.
Either execute the script by calling the system python:

/usr/bin/python /path/to/quartzfilter.py <input file> <filter> <output file>

It's a bit of a mouthful!

Or you will need to install the PyObjC library into your python. https://pypi.org/project/pyobjc/

pip install pyobjc should work.

Okay, it took some work. It works with Python 2, not Python 3. Tried both. It also requires some care with the filenames, backslash before each space when running in Automator.

Yes, the bundled python that comes with Mac OS is python2. For it to work with python3, you just have to remove .decode('utf-8') from lines 46, 51, and 57.

Putting filenames in quotes will also stop the need for escaping spaces. But if you just want to create an Automator script that applies a set filter to selected files, then just modify the "Make PDF-X.workflow" Automator Service, which does that.