Error when building images using CLI

112 views
Skip to first unread message

Cory Wilson

unread,
Jun 5, 2022, 6:25:22 PM6/5/22
to PreTeXt support
Hello,

I have a question similar to the one located here: Error Cropping PDF Image Generating latex-image.  Specifically, pretext build -d is hanging on compiling the very first image in my project.  The code for the image is on Github here, lines 158-177.

Until a few days ago, I was using xsltproc to compile my pretext, and everything worked fine; in fact, I copied the 

Here's what I get when doing pretext support: 

------
PreTeXt-CLI version: 0.6.3
    PyPI link: https://pypi.org/project/pretextbook/0.6.3/
PreTeXt core resources commit: a9436d6f8f5d3cda3239d6e2fc56c82c72bc32d8
OS: Windows-10-10.0.19043-SP0
Python version: 3.10.4
Current working directory: C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext
PreTeXt project path: C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext
-----

After running pretext -v DEBUG build -d, this is what I get:

--------
Traceback (most recent call last):
  File "C:\Python310\lib\shutil.py", line 813, in move
    os.rename(src, real_dst)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'cropped-image-1.pdf' -> 'image-1.pdf'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Python310\Scripts\pretext.exe\__main__.py", line 7, in <module>
  File "C:\Python310\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "C:\Python310\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "C:\Python310\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Python310\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Python310\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "C:\Python310\lib\site-packages\pretext\cli.py", line 239, in build
    project.build(target_name,webwork,diagrams,diagrams_format,only_assets,clean)
  File "C:\Python310\lib\site-packages\pretext\project.py", line 269, in build
    builder.diagrams(
  File "C:\Python310\lib\site-packages\pretext\build.py", line 61, in diagrams
    core.latex_image_conversion(
  File "C:\Python310\lib\site-packages\pretext\static\pretext\pretext.py", line 384, in latex_image_conversion
    shutil.move("cropped-"+latex_image_pdf, latex_image_pdf)
  File "C:\Python310\lib\shutil.py", line 833, in move
    copy_function(src, real_dst)
  File "C:\Python310\lib\shutil.py", line 434, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "C:\Python310\lib\shutil.py", line 254, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'cropped-image-1.pdf'
PTX: converting latex-image pictures from C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext\source\main.xml to svg graphics for placement in C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext\generated-assets\latex-image
PTX:DEBUG: temporary directory for latex-image conversion: C:\Users\User\AppData\Local\Temp\tmphvomsljf
PTX: extracting latex-image pictures from C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext\source\main.xml
PTX: string parameters passed to extraction stylesheet: {'publisher': 'C:/users/user/dropbox/school/ou/20222023/1914fa22/notes/pretext/publication/publication.ptx'}
PTX: discovering source file's directory name: C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext\source
PTX: verifying and expanding input directory: C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext\source\../generated-assets
PTX: input directory expanded to absolute path: C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext\generated-assets
PTX: verifying and expanding input directory: C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext\source\../assets
PTX: input directory expanded to absolute path: C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext\assets
PTX: XSL conversion of C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext\source\main.xml by C:\Python310\lib\site-packages\pretext\static\xsl\extract-latex-image.xsl
PTX:DEBUG: XSL conversion via C:\Python310\lib\site-packages\pretext\static\xsl\extract-latex-image.xsl of C:\users\user\dropbox\school\ou\20222023\1914fa22\notes\pretext\source\main.xml to None and/or into directory C:\Users\User\AppData\Local\Temp\tmphvomsljf with parameters {'publisher': 'C:/users/user/dropbox/school/ou/20222023/1914fa22/notes/pretext/publication/publication.ptx'}
PTX:DEBUG: locating "xelatex" in [executables] section of configuration file
PTX:DEBUG: xelatex executable: xelatex, options:
PTX:DEBUG: tex executable: xelatex
PTX: converting image-1.tex to image-1.pdf
PTX:DEBUG: locating "pdfcrop" in [executables] section of configuration file
PTX:DEBUG: pdfcrop executable: pdf-crop-margins, options:
PTX: cropping image-1.pdf to cropped-image-1.pdf
PTX:ERROR: There was a problem cropping image-1.pdf and cropped-image-1.pdf was not created
------

It seems like the issue somehow has something to do with the cropping of the image, but I have pdfcropmargins installed and updated.  Again, I don't see this issue showing up when running xsltproc, only when trying to run build via the CLI.

Is this just user error?

Cory

Rob Beezer

unread,
Jun 6, 2022, 1:49:38 PM6/6/22
to pretext...@googlegroups.com
Dear Cory,

Yes, it seems like the cropping is failing.

1. Try commenting out your first image and see if it fails on the second one?

2. The action happens in a temporary directory, for the log you posted, you can
see:

> PTX:DEBUG: temporary directory for latex-image conversion: C:\Users\User\AppData\Local\Temp\tmphvomsljf

It'll change every run. You can try running the cropping step manually and see
if that is informative.

3. The pretext/pretext script uses much of the same code. You can try that in
a virtual Python enviroment - slightly easier to debug perhaps, and slightly
different from the CLI.

4. Mostly I'm just bumping this thread - the main CLI developers are not seeing
all their email right now.

Rob



On 6/5/22 15:25, Cory Wilson wrote:
> Hello,
>
> I have a question similar to the one located here: Error Cropping PDF Image
> Generating latex-image
> <https://groups.google.com/g/pretext-support/c/xEk9cWoFBMU>.  Specifically,
> pretext build -d is hanging on compiling the very first image in my project.
> The code for the image is on Github here
> <https://github.com/cg2wilson/1914fa22notes/blob/main/source/ch1/11.xml>, lines
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pretext-suppo...@googlegroups.com
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/3bbd06ce-ee6b-4d4c-8dea-4ebe3446d60bn%40googlegroups.com
> <https://groups.google.com/d/msgid/pretext-support/3bbd06ce-ee6b-4d4c-8dea-4ebe3446d60bn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Steven Clontz

unread,
Jun 7, 2022, 1:44:13 PM6/7/22
to PreTeXt support
Nothing springs to mind. Do you have a GitHub repo or minimum working example you can share?

Cory Wilson

unread,
Jun 7, 2022, 5:07:10 PM6/7/22
to PreTeXt support
@Rob: I commented out the first image (the one that created image-1.tex and image-1.pdf) and reran, but the issue persisted instead on image-10.pdf rather than image-1.pdf.  

I tried using pdf-crop-margins by itself, and now it looks like pdfCropMargins is having trouble locating pyPDF2.  I did pip uninstall pypdf2 and pip install pypdf2 (and the pip3 version of the commands) to see if that would help, but nothing so far.  I'm still in the process of trying to track down this particular error, but no luck so far.

@Steven: the files are located at https://github.com/cg2wilson/1914fa22notes.  The image is located specifically in /source/ch1/11.xml.

Cory

Cory Wilson

unread,
Jun 9, 2022, 2:26:21 PM6/9/22
to PreTeXt support

I solved the problem.  There is a discrepancy between the current code of pdfCropMargins and the current version of PyPDF2; downgrading to PyPDF2 v1.26.0 resulted in a clean build.

Rob Beezer

unread,
Jun 13, 2022, 11:36:27 AM6/13/22
to pretext...@googlegroups.com
Thanks, Cory, for reporting back. There's an issue now for looking into this:

https://github.com/PreTeXtBook/pretext-cli/issues/240

On 6/9/22 11:26, Cory Wilson wrote:
>
> I solved the problem.  There is a discrepancy between the current code of
> pdfCropMargins and the current version of PyPDF2; downgrading to PyPDF2 v1.26.0
> resulted in a clean build.
> On Tuesday, 7 June 2022 at 16:07:10 UTC-5 Cory Wilson wrote:
>
> @Rob: I commented out the first image (the one that created image-1.tex and
> image-1.pdf) and reran, but the issue persisted instead on image-10.pdf
> rather than image-1.pdf.
>
> I tried using pdf-crop-margins by itself, and now it looks like
> pdfCropMargins is having trouble locating pyPDF2.  I did pip uninstall
> pypdf2 and pip install pypdf2 (and the pip3 version of the commands) to see
> if that would help, but nothing so far.  I'm still in the process of trying
> to track down this particular error, but no luck so far.
>
> @Steven: the files are located at https://github.com/cg2wilson/1914fa22notes
> <https://github.com/cg2wilson/1914fa22notes>.  The image is located
> <https://groups.google.com/d/msgid/pretext-support/3bbd06ce-ee6b-4d4c-8dea-4ebe3446d60bn%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/pretext-support/3bbd06ce-ee6b-4d4c-8dea-4ebe3446d60bn%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pretext-suppo...@googlegroups.com
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/12e56d70-ac07-43b2-8e46-86f7908ed1e7n%40googlegroups.com
> <https://groups.google.com/d/msgid/pretext-support/12e56d70-ac07-43b2-8e46-86f7908ed1e7n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Steven Clontz

unread,
Jun 13, 2022, 5:40:39 PM6/13/22
to PreTeXt support
@cory sorry if you're getting this twice but I cannot find where I thought I sent this the first time.

Please try to 

pip install --upgrade pypdf2

to the latest version and see if that works.

Cory Wilson

unread,
Jun 13, 2022, 7:13:46 PM6/13/22
to PreTeXt support
I get the same issue when trying to use pretext build -d html: PTX: ERROR: There was a problem cropping image-1.pdf and cropped-image-1.pdf was not created

When I try to use pdfCropMargins by itself, I get the same error as before (and the same one that Oscar Levin posted in the Github Issues page).  

I haven't tried all version between pypdf2 v1.26.0 and 2.2.0, but 1.26.0 for sure has been working.

Steven Clontz

unread,
Jun 13, 2022, 7:15:48 PM6/13/22
to pretext...@googlegroups.com
Which version was installed when you ran

pip install --upgrade pypdf2

You received this message because you are subscribed to a topic in the Google Groups "PreTeXt support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pretext-support/bHNg69j_mCo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pretext-suppo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/ba91fba0-abaf-4f47-88e0-11b2d192d000n%40googlegroups.com.

Cory Wilson

unread,
Jun 14, 2022, 12:40:50 AM6/14/22
to PreTeXt support
pyPDF2 installed version v2.2.0

Steven Clontz

unread,
Jun 14, 2022, 2:18:14 PM6/14/22
to PreTeXt support
Thanks Cory - the change in pypdf2 breaking pdfcropmargins was in fact reverted temporarily in a 1.x update, but reintroduced (as allowed with major releases) in the major 2.0 release a few days back. I've suggested pdfcropmargins be updated to address this at https://github.com/abarker/pdfCropMargins/issues/36 but for now I've hardwired a working pypdf2 version in the next CLI release at https://github.com/PreTeXtBook/pretext-cli/commit/0a5bfd8b1f897504c188aabd49978a390faffb19

For now the solution is to manually pip install a working version like you suggsted, such as

python -m pip install pypdf==1.28.4 #last <2.0 release

Reply all
Reply to author
Forward
0 new messages