I am trying to get pythonTeX running with Lyx 2.4.1 in Windows 10 by following this post. I have installed pythonTeX and verified it is working when running a test file with the commands:

  1. pdflatex test.tex (this generates pytx code)
  2. pythontex.bat test.tex (parses pytx code)
  3. pdflatex test.tex (this generates pdf)

In Lyx, I set up the file formats as discussed in the previous post:

  1. format=LaTeX (pytex1); shortname=pytex1; extensions=pytex1ext
  2. format=LaTeX (pytex2); shortname=pytex2; extensions=tex
  3. format=PDF (pytex); shortname=pytex; extensions=pdf

And converters:

  1. from=LaTeX (pdflatex); to=LaTeX (pytex1); converter=pdflatex $$i; extra=latex=pdflatex
  2. from=LaTeX (pytex1); to=LaTeX (pytex2); converter=pythontex.bat $$i; extra=``
  3. from=LaTeX (pytex2); to=PDF (pytex); converter=pdflatex $$i; extra=latex=pdflatex

which follows the test run described above.

This isn't working as expected; step 1 of the conversion works fine, i.e. pdflatex is run on the tex file to create the pytx code. However, step 2 fails with the following message:

09:11:07.158: pythontex.bat "test.pytex1ext"
09:11:07.193: C:\Users\xxx\AppData\Local\Temp\lyx_tmpdir>python "c:/users/xxx/documents/localtexmf/scripts/pythontex/pythontex.py" test.pytex1ext 
09:11:07.575: Traceback (most recent call last):
09:11:07.580:   File "c:/users/xxx/documents/localtexmf/scripts/pythontex/pythontex.py", line 50, in <module>
09:11:07.584:     import pythontex2 as pythontex
09:11:07.587:   File "c:\users\xxx\documents\localtexmf\scripts\pythontex\pythontex2.py", line 60, in <module>
09:11:07.590:     import multiprocessing
09:11:07.592: ImportError: No module named multiprocessing
..\..\..\src\support\Systemcall.cpp (292): Systemcall: 'pythontex.bat "test.pytex1ext"' finished with exit code 1
Error: Cannot convert file

This fails obviously because in C:\Users\xxx\AppData\Local\Temp\lyx_tmpdir there is no file test.pytex1ext which is the extension defined in format 1 but just the file test.tex. So what happens when i change the extension to tex instead? Then the second step tries to run:

pythontex.bat 'tmpfile.out'

which obviously also does not exist. Who has an idea how to sort this out? I am close but can't get it to work.

Note: The ImportError on the multiprocessing module worries me slightly as well as it is working fine when running pythotex.bat from the command prompt, but i want to get the extension right first and see if the issue remains.


As it turns out the ImportError was part of the problem; apparently LyX uses its own version of Python. To remedy this i replaced the version of Python with a softlink to my installed version of Python. Alternatively, you could set the correct PATH variable in the preferences.

The second thing which caused problems was the creation of the pdf in step 1; Lyx won't compile a new pdf if a pdf is already present. A quick workaround for me was to insert the following lines into pythontex.bat before the call to pythontex.py:

set argin=%1
del %argin:pytex1ext=pdf%

Note that this will skip any other generated pdf in case such files are used as image formats with vector graphics.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.