3

I’m looking forward to running the memoize package to reduce my compile time, but after several days of research, I’m clueless. This is my first Python rodeo, so I may be missing something that to others would be obvious. Initially thought it was a path mismatch, but now I’m not so sure.

Configuration (Mac running Python 3.13.1 on Sequoia 15.1.1, compiling w LuaLaTeX using TeXShop 5.47):

  1. My memoize.cfg is:
\mmzset{
  extract=python,    % Use the Python-based extern extraction method.
  auto={circuitikz}{memoize},   % Working on electrical circuits
  prefix=memos/,    % Use one memo directory for all documents in a folder.
 }
  1. Terminal command python -c 'import sys; print("\n".join(sys.path))’ yields:
/Library/Frameworks/Python.framework/Versions/3.13/lib/python313.zip
/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13
/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/lib-dynload
/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages
  1. Terminal command pip show pdfrw2 yields:
Name: pdfrw2
Version: 0.5.0
Summary: PDF file reader/writer library
Home-page: https://github.com/sarnold/pdfrw
Author: Patrick Maupin
Author-email: [email protected]
License: MIT
Location: /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages
Requires:
Required-by:
  1. My MWE memoize.tex (from Sec 2.1 in Memoize v1.4.1 December 2, 2024 package documentation):
\documentclass{article}
\usepackage{tikz,forest}

\usepackage[recompile]{memoize}

\begin{document}

Memoize will automatically externalize\\
\begin{tikzpicture}
    \node(node)
        [align=center,ellipse,draw]
        {TikZ\\pictures};
\end{tikzpicture}

\begin{forest}
    [and Forest trees [and]
    [Forest trees[Forest][trees]]]
\end{forest}

\end{document}

Results in the following console error:

memoize-extract.py: Python module 'pdfrw' was not found.
Have you followed the instructions is section 1.1 of the manual?
 (./memoize.mmz.log

./memoize.mmz.log:1: Package memoize (python-based extraction) Error: Python module 'pdfrw' was not found.

Note 1: I used pip 24.3.1 to install/uninstall/reinstall the Python module ’pdfrw2’ (as well as ’pdfrw’) several times. No luck.

Note 2: The documentation states: … install Python and library pdfrw2 and then use extract=python. It says nothing about installing pdfrw [w/o the 2].

Note 3: [From 2. above] The sys.path includes the path: /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages which [From 3. above] is identical to the location of pdfrw2: /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages.

This makes me think it’s not a path mismatch.

Lastly, I have no idea why the console error states that the pdfrw module is missing, when the documentation clearly states that memoize requires the pdfrw2 module.

What am I missing?


UPDATE as of Jan 10, 2025:


I still have no resolution to the Warning issue that is halting execution of my memoize6.tex LuaLaTeX file midway. The Warning message that I continue to see includes:

LaTeX Warning: You have requested package `/usr/local/texlive/2024/texmf-dist/t
ex/latex/memoize/memoize',
               but the package provides `memoize'.

(/usr/local/texlive/2024/texmf-dist/tex/latex/advice/advice.sty
(/usr/local/texlive/2024/texmf-dist/tex/latex/collargs/collargs.sty))
memoize-extract.py: Logging to 'memoize6.mmz.log'.
memoize-extract.py: Python module 'pdfrw' was not found.
Have you followed the instructions is section 1.1 of the manual?

(./memoize6.mmz.log

./memoize6.mmz.log:1: Package memoize (python-based extraction) Error: Python m
odule 'pdfrw' was not found.

Why the Warning is stating that:

You have requested package `/usr/local/texlive/2024/texmf-dist/t
ex/latex/memoize/memoize',
               but the package provides `memoize’.

is baffling to me. To me this says the LuaLaTeX package actually found the memoize.sty file, but for some reason it does not like what it found is contained inside the memoize.sty file??

I’ve been trying so many iterations to solve this issue that it may be important that I re-post my most recent version of my memoize6.tex file with the added pygmentex pycode that I’ve added, but hasn’t altered the result:

\documentclass[12pt,letterpaper]{article}
\usepackage{comment}
\usepackage{pygmentex}
\usepackage[runall=true,debug]{pythontex}

% \begin{comment}
   \begin{pycode}
   % import sys
   % sys.path.append("/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages")
   % import pdfrw
   % python -m venv memoize_env
   python -m pip install pdfrw2
   source memoize_env/bin/activate
   pip install pdfrw2
   import pdfrw2
   export PYTHON=`which python`
   \end{pycode}
% \end{comment}

% \usepackage[trace,extract=python]{memoize}
\usepackage[trace,extract=python]{/usr/local/texlive/2024/texmf-dist/tex/latex/memoize/memoize}

\usepackage{tikz}
\usepackage{forest}

\title{memoize6}

\begin{document}

Memoize will automatically externalize\\

\begin{tikzpicture}
    \node(node)
    [align=center,ellipse,draw]
    {TikZ\\pictures};
\end{tikzpicture}

\vspace{-2.0cm} % \vspace added to adjust the location of the 'forest'
\hspace{2.5cm}  % \hspace added to adjust the location of the 'forest'
\begin{forest}
    [and Forest trees [and]
    [Forest trees[Forest][trees]]]
\end{forest}
    
\end{document}

I will continue to search for what is causing the Warning to halt execution of my LuaLaTeX code before attempting to add the memoize package to my larger LuaLaTeX project.

All suggestions/thoughts appreciated. (I can send copies of my memoize6.log file for those who may be interested in assisting.)

Thank you everyone for all for your assistance.


UPDATE as of Jan 13, 2025: (Note: As of 22 Jan 2025, this update has been moved to Answer # 3)


33
  • are you actually using that .tex file as-is? I posted an answer, but I've deleted it as I'm not sure it's the problem, but you have to load memoize before either tikz or forest. Commented Dec 11, 2024 at 15:31
  • can you try compiling on the command line? pdfrw2 calls itself pdfrw as far as I can tell. Commented Dec 11, 2024 at 15:37
  • 1
    also, can you run the extraction manually i.e. does the extraction work if you do it as a standalone step? Commented Jan 10 at 8:25
  • 1
    can you post your final update as an answer rather than putting it into the question? it is confusing if the answer is inside the question and self answers are perfectly fine. you should also accept your own answer so it ends up on top. (you may lose 2 points for doing this - I'm not sure.) Commented Jan 14 at 18:55
  • 1
    I really glad you managed to resolve this! A couple of thoughts: (a) I believe that setting the path is what made the crucial difference. (b) On Linux, /usr/bin/python and /usr/bin/python3 are symlinks to a specific version, maybe changing that would've helped as well. (c) You have not completely removed the unwanted python versions. In particular, each version also has files in /usr/lib/python<version>. Commented Jan 15 at 7:54

4 Answers 4

2

[Not an answer; too messy/long for a comment.]

Python extraction works for me with:

$ pip show pdfrw
Name: pdfrw
Version: 0.4
Summary: PDF file reader/writer library
Home-page: https://github.com/pmaupin/pdfrw
Author: Patrick Maupin
Author-email: [email protected]
License: MIT
Location: /usr/lib/python3.12/site-packages
Requires:
Required-by:

According to the manual, either pdfrw or pdfrw2 should work (p 28). Sometimes GUI editors don't use the same environment as the CLI. To test if this might be the problem, try compiling on the command line, where you know python finds the library.

You need to load memoize before loading tikz or forest.

\documentclass{article}

\usepackage[extract=python]{memoize}
\usepackage{tikz,forest}

\begin{document}

Memoize will automatically externalize

\begin{tikzpicture}
  \node(node)
  [align=center,ellipse,draw]
  {TikZ\\pictures};
\end{tikzpicture}

\begin{forest}
  [and Forest trees [and]
    [Forest trees[Forest][trees]
    ]
  ]
\end{forest}

For comparison:

$ python -c 'import sys; print(sys.path)'
['', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/usr/lib/python3.12/site-packages']
2

I don't own a MAC so I'm afraid I cannot offer a definitive solution (even if I'm the author of Memoize), but I believe the problem might be multiple Python installations, as hinted in the comments to the question. In other words, it might be that package pdfrw2 is not installed the same Python that TeX is accessing.

I can only offer an idea for a very hacky way of installing the package in the correct Python: from TeX, with shell escape. This should guarantee that the package is installed in the Python accessed by TeX, but beware that you should follow this suggestion at your own risk.

Put the following into a file, say install-pdfrw2.tex:

\immediate\write18{%
  python -m pip install pdfrw2
}
\bye

and execute (from the command-line):

pdftex -shell-escape install-pdfrw2

I believe that installed in this way, the library should be available under all TeX engines, including LuaTeX used by the OP. If not, replacing pdftex in this command line by luatex should do the trick.

As also mentioned in the comments, the package which needs to be installed is named pdfrw2 on PyPI, but this package provides module pdfrw. I agree this is somewhat confusing. I'm guessing the situation arose because package pdfrw2 is a fork of package pdfrw, and the module name wasn't changed for compatibility.

UPDATE (Jan 12)

Let's gather some further information. Please create file sysinfo.py with the following contents:

import sys
print("__file__:", __file__)
for attr in ('argv', 'executable', 'version', 'prefix', 'exec_prefix', 'base_prefix', 'base_exec_prefix', 'path'):
    print(f"sys.{attr}:", getattr(sys, attr))

Execute this from within TeX: create the sysinfo.tex and execute it via pdftex -shell-escape syinfo.

\immediate\write18{%
  python sysinfo.py
}
\bye

Ideally, if the system allows you to do so, you could put the contents of sysinfo.py into memoize-extract.py (at the top, just after imports) and see what's printed out then. (And if the information we gather turns out to be useful, I'll include this debug code in the script in the next release.)

13
  • Thank you for your suggestions. I followed your .tex and command-line suggestions, but the result is unchanged. What I now suspect is the the resulting output: ` Python module 'pdfrw' was not found. Have you followed the instructions is section 1.1 of the manual? ` is not the real, actual warning, but instead the Error message I see originates from the text within the memoize.sty file that clearly states the exact same text. The actual error that is triggering the Warning message I see is being hidden and I don’t know how to find out what that actual error is. Does that make any sense? Commented Jan 11 at 5:43
  • I believe the warning is real, as memoize.sty is designed to propagate the error from script memoize-extract.py, which should be the ultimate source of the error. Commented Jan 12 at 6:48
  • I don't think this is quite accurate. I'm using the unforked pdfrw because that's what my distro provides and it works fine. (maybe there are bugs, but it works for memoize.) Commented Jan 12 at 6:48
  • What was the output (or log) from the command line above? Commented Jan 12 at 6:48
  • 1
    I still think it would be worth knowing 2 things I asked about above: if python is run interactively, does import pdfrw work? and does the extraction script work on the command line if run by itself? the first ought to work, if pdfrw was installed with pip on the command line. but then you'd expect the extraction to work there, too, though it might not if env does something odd. Commented Jan 12 at 6:52
1

As of Jan 13, 2025:


I am posting here an AI summary of what I, cfr, Sašo Živanović and the AI have worked on for some time. I’ve had no prior experience working with Python, so this issue was a challenge. Someone, somewhere, sometime may be able to use what happened here and move forward.


Here’s a summary of the steps we took to resolve the Python module 'pdfrw' was not found. issue that arose from the multiple Python versions issue on my Mac:

Summary of Steps to Manage Python Versions on macOS

  1. Identified Installed Python Versions:
  • Used the command python3 -m site to check the installed Python versions and their locations.
  • Found that Python 3.9.6 was installed in /usr/bin, which is the system-installed version.
  1. Checked for Other Python Installations:
  • Used ls /usr/local/bin | grep python to identify additional Python versions (3.13 and 3.14) installed in /usr/local/bin.

Other Python Installations 3.13 and 3.14

  1. Removed Unwanted Python Versions:
  • Executed commands to remove the unnecessary Python versions from /usr/local/bin to clean up the environment.

Other Unwanted Python Versions 3.13 and 3.14 Removed

  1. Verified Current Python Version:
  • Confirmed that the system Python version (3.9.6) was still accessible by running python3 -V.
  1. Addressed PATH Issues:
  • Noticed a warning about pip scripts not being in the PATH.
  • Edited the shell configuration file (e.g., ~/.zshrc) to add export PATH="$PATH:/Users/koolstofgenesis/Library/Python/3.9/bin” to add /Users/<user_name>/Library/Python/3.9/bin to the directory PATH.
  1. Applied Changes and Verified:
  • Sourced the configuration file (source ~/.zshrc) to apply the changes and verified (echo $PATH) that the PATH was updated correctly.
  • Updated the pip command using /Library/Developer/CommandLineTools/usr/bin/python3 -m pip install --upgrade pip.
  • Tested the pip command to ensure it was working properly.
  1. Reinstalled the Python pdfrw2 module using pip3 unto the Python system-installed version 3.9.6:
  • pip3 install pdfrw2.
  1. Retested the memoize LaTeX code that utilizes the memoize Python pdfrw module. Now it Works!
\documentclass[12pt,letterpaper]{article}

\usepackage[extract=python]{memoize}

\usepackage{tikz}
\usepackage{forest}

\title{memoize}

\begin{document}

Memoize will automatically externalize\\

\begin{tikzpicture}
    \node(node)
    [align=center,ellipse,draw]
    {TikZ\\pictures};
\end{tikzpicture}

\vspace{-2.0cm}     % \vspace added to adjust the vertical location of the 'forest'
\hspace{2.5cm}      % \hspace added to adjust the horizontal location of the 'forest'
\begin{forest}
    [and Forest trees [and]
    [Forest trees[Forest][trees]]]
\end{forest}
    
\end{document}

Key Takeaways

  • Managing Python Versions: It's important to keep track of installed Python versions and clean up any unnecessary installations to avoid conflicts.
  • Setting Up the Environment: Properly configuring the PATH is crucial for accessing installed scripts and tools easily.
  • Using Built-in Tools: Utilizing built-in commands and shell configuration files can help manage the development environment effectively.
3
  • @Sašo Živanović - Thank you for your note. What I’m finding is that, after I had deleted all Python Homebrew versions, my Homebrew is unwittingly reinstalling Python version 3.13. It turns out, however, that that is NOT interfering with the memoize LuaLaTeX/Python implementation. FYI, I use your LaTeX test.tex code on Pg. 9 (Section 2.1) in your documentation as a quick check that the Python code continues to work with my LuaLaTeX. A perfect way to check if anything has changed. Thank you for including that in your documentation! Commented Jan 23 at 4:32
  • thanks! on TeX SE (but not all SE sites), it is fine to post an answer derived from AI provided you say that's what you're doing. that is, you should attribute it to the AI the same way you'd attribute code to another human more-or-less. note that some SE sites ban AI, so don't do this on another site without checking the local ordinances. Commented Jan 23 at 5:21
  • my guess is PATH differs when you're at the command line running pip vs compiling .tex files. it might be a bit more complicated e.g. it might be the library search path python uses or some combination. maybe homebrew changes or tells you to change PATH so that the versions it installs are preferred. but when you are compiling .tex files, you're getting the system python, so the PATH is either different or you're specifying an absolute path to the binary. or else the library path is set for the wrong python. (they're not called 'libraries' in python, but I forget what.) Commented Sep 28 at 1:38
0

What I found was that brew had re-installed Python on my Mac which somehow interfered with Python finding the pdfrw module when I tried running my LaTeX memoize package, thus returning me to the pdfrw module not found error I had worked so hard to eliminate.

Unable to properly install the path to the Python pdfrw module so that the pdfrw module could be located by the LaTeX memoize package, I was left with the only remaining alternative but to un-install ALL Python versions on my Sequoia Mac, except for the Python system version.

To un-install all brew’ed Python versions, I employed the 2nd answer instructions to: Uninstalling python3 on MacOs, at https://stackoverflow.com/questions/60280377/uninstalling-python3-on-macos by running brew uninstall [email protected] to remove the brew’ed Python version 3.13 et al. from my Mac.

Then, I followed the instructions outlined in the 2nd answer to: How can I safely uninstall one version of python without removing others? at https://stackoverflow.com/questions/44231329/how-can-i-safely-uninstall-one-version-of-python-without-removing-others to un-install any non-brew'ed Python versions (without touching the system version of Python) that were left after I had un-installed all the brew’ed versions of Python.

I then attempted to re-install the Python pdfrw module that was needed by the LaTeX memoize package.

With just the Python system version installed, when I attempted to re-install the pdfrw module, I received a message “Error: Current platform "darwin 24" does not match expected platform "darwin 23”. So I followed the MacPorts instructions to update my Sequoia system (Install MacPorts for your version of the Mac operating system:) at: https://www.macports.org/install.php. The MacPorts installation went smoothly.

Lastly, to re-install the Python pdfrw module, I followed the instructions sudo port install py27-pdfrw to install the py27-pdfrw Python module (at: https://ports.macports.org/port/py27-pdfrw/).

It all worked! I was able to run the MWE test.tex LaTeX code (on Page 9 in Section 2.1 of the Memoize documentation by Sašo Živanovic, the package author) without encountering the dreaded pdfrw module not found error.

Now I just need to stop brew from re-installing those Python packages.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.