0

I would like to use PythonTex in Lyx on a Mac. I don't understand the intricacy of Lyx/Tex etc. I think I managed to install PythonLex by installing MacTex 2021 which also installed Tex Live Utility and if I use it to look at packages it also installed pythonlex.

I found this question StackExchange Question

Not sure how I enter the \xxxx statements into a document so tried

Document | Setting | Latex Preamble

And pasted info from article.

When I tried to display the PDF I found it did not like the first two lines with inputenc and fontenc

What it displayed was enter image description here

I would like to be able to enter matplotlib python into my document that display plots & charts, Please advise

  • Hello, first, you should always endeavour to put in an Minimal compilable example of your issue for others to test. Your issue is very general, so I try to help, but as of now only in general way. First things first -- pythontex in a script file pythontex.py ; which should be locatable in your terminal. Are you able to find executable file pythontex in your $PATH? I am not familiar with LyX, but your error apell that you havent run pythontex on your file. If you want to use pythontex, you have to run latex compiler, then pythontex, then again latex compiler to get the results. – Tomáš Kruliš Aug 05 '21 at 07:38
  • Example is as per the linked StackExchanged Question. I just tried unsuccessfully to do the same. If I go to a command line console then I get keithsloan@Keiths-iMac GDML % pythontex Traceback (most recent call last): File "/Library/TeX/texbin/pythontex", line 50, in import pythontex2 as pythontex File "/usr/local/texlive/2021/texmf-dist/scripts/pythontex/pythontex2.py", line 61, in from pygments.styles import get_all_styles ImportError: No module named pygments.styles – Keith Sloan Aug 05 '21 at 12:06
  • In TexLog I see No file pythontex-files-TestPythonTex-A/TestPythonTex-A.pytxmcr. Run PythonTeX to create it. Package newfloat Info: New float listing' with optionsfileext=lopytx' on inp ut line 20. \c@listing=\count288 \newfloat@ftype=\count289 Package newfloat Info: float type `listing'=8 on input line 20. (/usr/local/texlive/2021/texmf-dist/tex/context/base/mkii/supp-pdf.mkii [Loading MPS to PDF converter (version 2006.09.02).] – Keith Sloan Aug 05 '21 at 12:11
  • From those errors seems that you dont have pygments python package installed. Have you ever installed pygments with pip? – Tomáš Kruliš Aug 05 '21 at 12:12
  • I have not, but I suspect it might have been installed as part of Mac Tex 2021 as if I try pip3 install pygments it tells me the requirement is already satisfied – Keith Sloan Aug 05 '21 at 12:15
  • Have you installed both python2 and python3 on your Mac? I am not using Mac, nor LyX, but this also could be caused by naming of your python binaries. – Tomáš Kruliš Aug 05 '21 at 12:19
  • If I just enter python I get Python 2.7.16 and if i enter python3 I get python 3.9.5 – Keith Sloan Aug 05 '21 at 12:24
  • Looking at https://tug.org/TUGboat/tb34-3/tb108mertz.pdf It says one has to Three steps are needed to process a PythonTEX The document sample.tex could be processed with the following sequence of commands. pdflatex -interaction nonstopmode \ -draftmode sample.tex pythontex sample.tex pdflatex sample.tex

    Lyx to display the PDF one invokes via Document | View PDF which just invokes pdflatex. So don't know how one would run the three commands under Lyx (GUI)

    – Keith Sloan Aug 05 '21 at 12:29
  • Okay I found this link https://tex.stackexchange.com/questions/114285/pythontex-workflow-with-lyx/114708#114708 seems to give info on how to get Lyx to run alternate commands – Keith Sloan Aug 05 '21 at 12:35
  • When I run now I get an error An error occurred while running: pythontex "TestPythonTex-A.pytexs1extension" and when I do the same from the command line I get pythontex "TestPythonTex-A.pytexs1extension" Traceback (most recent call last): File "/Library/TeX/texbin/pythontex", line 50, in import pythontex2 as pythontex File "/usr/local/texlive/2021/texmf-dist/scripts/pythontex/pythontex2.py", line 61, in from pygments.styles import get_all_styles ImportError: No module named pygments.styles – Keith Sloan Aug 05 '21 at 14:49
  • When you run pythontex it by default starts python binary -- in your case that is python v. 2 actually. Look in pythontex docs, there should be info about how to set pythontex to use python3 and not python binary. I personally uninstalled python2 and using only python3, but I dont know if that is OK on Mac. Other option would be to install pygments with python2, not python3 (but I dont know how to issue that with pip). – Tomáš Kruliš Aug 05 '21 at 17:30
  • Tried install with pip2 install pygments and said it was okay, but still problems. Get error An error occurred while running: pythontex "TestPythonTex-A.pytexs1extension"

    If I try from command line I getpythontex TestPythonTexA.pytexs1extension Not sure it will find the file

    • PythonTeX error Code file TestPythonTexA.pytxcode does not exist. Run LaTeX to create it.

    Would help if I could check the directory where the temp files are but mission impossible on mac.

    – Keith Sloan Aug 05 '21 at 18:20
  • Did you ran latex - pythontex - latex? Also, have you installed latex from texlive, or some Mac package? – Tomáš Kruliš Aug 05 '21 at 18:47
  • As per original post installed MacTex 2021 which also installed Tex Live – Keith Sloan Aug 05 '21 at 18:51
  • When I am creating the step1 file can I add anything to the converter command pdflatex $$i to direct the output somewhere under my control? From format: LaTeX(LuaTeX) To format: PythonTeXStep1 Converter: pdflatex $$i – Keith Sloan Aug 05 '21 at 19:18
  • Well, I am not versed with setting up LyX, never used it. If that is acceptable for your, I would suggest using either command line or TeXworks to find out if pythontex is working on your setup and after that throw in LyX. For that, you would have to find someone who is using LyX. – Tomáš Kruliš Aug 06 '21 at 06:59
  • Thanks for trying to help. This is unusable as it is without writing out files and logs in meaningful places. Limitation of Lyx or at least my knowledge of it. – Keith Sloan Aug 06 '21 at 14:11
  • Document | LaTex Log - Offers a box 'Open Containing Directory' which gives access to the files. Might now make some progress. – Keith Sloan Aug 06 '21 at 17:07
  • View | Code Preview Pane gives access to any python errors – Keith Sloan Aug 06 '21 at 17:43

0 Answers0