0
\documentclass{ltjsarticle}

\usepackage{pythontex}

\begin{pycode}
def fizbuz(n):
    for i in range(1, n+1):
        if i % 3 == 0:
            print("fiz", end=' ')
        else:
            print(i, end=' ')
    return
\end{pycode}

\begin{document}
    \pyc{fizbuz(100)}
\end{document}

Running this code with Latex Workshop(on VSCode), I have the error: "env: python: No such file or directory". My setting of Latex Workshop is following. How can I solve this problem?

P.S. I ran the above code on my M1 Mac and I surely installed python3.8 and pygments. The latex engine is LuaLaTeX (TeXLive2021).


    "latex-workshop.latex.recipes": [
        {
          "name": "toolchain",
          "tools": ["lualatex", "pythontex", "lualatex"]
        }
      ],
      "latex-workshop.latex.tools": [
        {
          "name": "lualatex",
          "command": "lualatex",
          "args": [
            "--cmdx",
            "-file-line-error",
            "-synctex=1",
            "-interaction=nonstopmode",
            "-halt-on-error",
            "%DOC%"
          ]
        },
        {
            "name": "pythontex",
            "command": "pythontex",
            "args": [
                "%DOC%"
            ]
        },
      ]
New contributor
nekko is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

2 Answers 2

0

Sorry this is no direct answer to your problem, but from my own experience (and because you are already using LuaLaTeX, I can really recommend PyLuaTeX to you. It makes it a looot easier to include Python code in your TeX-files.

I use it a lot when I create plots with pgfplots because I find it easier to manage certain variables such as column names, length of lists, …

Also you DO NOT need to compile longer or extra because the code is executed on the fly.

CTAN: https://ctan.org/pkg/pyluatex?lang=en

Example (just compile with lualatex and --shell-escape):

\documentclass{scrartcl}
\usepackage[executable=python, verbose]{pyluatex} 
% this tells PyLuaTex what your executable in the conosle is, 
% e.g. python, py3, python3, …
% verbose tells PyLuaTeX to print the input and output to the log if you want to see 
% your code being executed

\begin{document}
Hello this a test document. 
We can use python like \py{"this"} or in an environment like this:
\begin{python}
     a = 2 
     b = 3
     c = a * b
     print(c)
\end{python}
% The output is then (obviously) 6. 
\end{document}
0
0

I copied/pasted your recipes and tools snippets in my settings.json but putting the tools item before the recipes one.It worked.

This is my settings.json

{
    "terminal.integrated.shell.linux": "/bin/bash",
    "editor.fontSize": 11,
    "git.suggestSmartCommit": false,
    "window.zoomLevel": 1,
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": false,
    "python.dataScience.alwaysTrustNotebooks": true,
    "haskell.trace.server": "messages",
    "security.workspace.trust.untrustedFiles": "open",
    "python.dataScience.sendSelectionToInteractiveWindow": true,
    "editor.minimap.enabled": false,
    "diffEditor.ignoreTrimWhitespace": false,
    "python.formatting.provider": "black",
    "editor.renderWhitespace": "none",
    "git.confirmSync": false,
    "latex-workshop.latex.tools": [
        {
          "name": "lualatex",
          "command": "lualatex",
          "args": [
            "--cmdx",
            "-file-line-error",
            "-synctex=1",
            "-interaction=nonstopmode",
            "-halt-on-error",
            "%DOC%"
          ]
        },
        {
            "name": "pythontex",
            "command": "pythontex",
            "args": [
                "%DOC%"
            ]
        },
      ]
    "latex-workshop.latex.recipes": [
        
        {
            "name": "toolchain",
            "tools": ["lualatex", "pythontex", "lualatex"]
        }   
        {
            "name": "latexmk 🔃",
            "tools": [
                "latexmk"
            ]
        },
        {
            "name": "latexmk (latexmkrc)",
            "tools": [
                "latexmk_rconly"
            ]
        },
        {
            "name": "latexmk (lualatex)",
            "tools": [
                "lualatexmk"
            ]
        },
        {
            "name": "latexmk (xelatex)",
            "tools": [
                "xelatexmk"
            ]
        },
        {
            "name": "pdflatex ➞ bibtex ➞ pdflatex × 2",
            "tools": [
                "pdflatex",
                "bibtex",
                "pdflatex",
                "pdflatex"
            ]
        },
        {
            "name": "Compile Rnw files",
            "tools": [
                "rnw2tex",
                "latexmk"
            ]
        },
        {
            "name": "Compile Jnw files",
            "tools": [
                "jnw2tex",
                "latexmk"
            ]
        },
        {
            "name": "tectonic",
            "tools": [
                "tectonic"
            ]
        }
    ]
}
1
  • Thank you for your comment. But unfortunately, in my environment, it don't work even though I put "tools" before "recipes". ><
    – nekko
    Jun 23 at 3:57

Your Answer

nekko is a new contributor. Be nice, and check out our Code of Conduct.

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.