1

When I try to run pythontex via my command line((base) Zachs-MacBook-Pro:mat_300 zachmaurus$ pythontex pythontex.tex) the following occurs:

Traceback (most recent call last):
  File "/Library/TeX/texbin/pythontex", line 50, in <module>
    import pythontex2 as pythontex
  File "/usr/local/texlive/2019/texmf-dist/scripts/pythontex/pythontex2.py", line 61, in <module>
    from pygments.styles import get_all_styles
ImportError: No module named pygments.styles

How do I go about solving this issue? I have downloaded pygments with pip install, but for whatever reason when I attempt to run the script the module pygments.style cannot be found.

  • 1
    Can you please post your python version ? I think your python package is installed on different python version than the one you're using. – Jay Patel Jan 03 '21 at 01:56
  • How did you go about installing Pygments, was this using Pip? If so can you supply the result of `pip list` – Peter Jan 03 '21 at 03:53

3 Answers3

0

Solved this issue by adding pythontex_install.py to my PATH using export PATH=$PATH:/usr/zachmaurus/Downloads/pythontex/pythontex_install.py in MacOS Terminal. To ensure that pythontex_install.py has been added to PATH environment run echo $PATH and it should appear as one of the variables. After having added pythontex_install.py to PATH, I now get the following result when I run pythontex pythontex.tex to compile my document:

This is PythonTeX 0.16

--------------------------------------------------
PythonTeX:  pythontex - 0 error(s), 0 warning(s) 
0

I solved this problem by explicitly call the interpreter I want, wenn I compile the document.

pdflatex -interaction=nonstopmode document.tex
python3 <path_to_pythontex.py>/pythontex.py document.tex
pdflatex -interaction=nonstopmode document.tex

or for any python interpreter you want:

pdflatex -interaction=nonstopmode document.tex
<path_to_python>/python3 <path_to_pythontex.py>/pythontex.py document.tex
pdflatex -interaction=nonstopmode document.tex

Of course Pygments module schuld be installed by this interpreter. This worked very good for me on macOS.

-2

I got the same problem when I tried to use pythontex on my macbook (on macOS Catalina 10.15).

What I suggest below must be (if used) used with precaution :

I tried so many solutions and what actually worked for me was this :

  • I made sure that pygments was installed on my machine (I ran 'pip install pygments' on the terminal)

  • Then I changed the first line of the files pythontex, pythontex2 (because the problem seemed to come from there) and pythontex3

Theses files (if you are using macOS Catalina 10.15 like me) should be in /usr/local/texlive/2021/texmf-dist/scripts/pythontex (if you installed TexLive2021) -> you should be able to retrieve this path when you try to compile your tex file anyway...

The first line was replaced by #!/usr/bin/python3 (to ensure that python3 was used instead of python 2.7 which is used by default by macOS) inside the 3 files pythontex, pythontex2 and pythontex3 then :

I ALSO added this line (see the screenshot below) in pythontex3 :

sys.path.append('/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/') to ensure that python found the module pygments (because I installed python3.9 on my machine and the folder "pygments" and its subfolder "styles" was present in the folder "site-packages")

pythontex3 file

So now everything is working fine again and I can use pythontex =)

Dharman
  • 30,962
  • 25
  • 85
  • 135