PythonTex 错误:VSCode 上没有该文件或目录

PythonTex 错误:VSCode 上没有该文件或目录
\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}

使用 Latex Workshop(在 VSCode 上)运行此代码时,出现错误:“env: python: 没有这样的文件或目录”。我的 Latex Workshop 设置如下。我该如何解决这个问题?

PS 我在我的 M1 Mac 上运行了上述代码,并且我当然安装了 python3.8 和 pygments。Latex 引擎是 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%"
            ]
        },
      ]

答案1

抱歉,这不能直接回答您的问题,但根据我自己的经验(并且因为您已经在使用,我真的可以向您推荐 PyLuaTeX。它使在您的文件中包含代码LuaLaTeX变得更容易。PythonTeX

我在创建图表时经常使用它,pgfplots因为我发现它更容易管理某些变量,如列名、列表长度等。

另外,您不需要进行更长时间或额外的编译,因为代码是即时执行的。

加拿大运输安全管理局:https://ctan.org/pkg/pyluatex?lang=en

示例(仅使用 和 进行编译lualatex--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}

答案2

我复制/粘贴了您的片段recipes, 但将工具项目放在了食谱之前。它起作用了。toolssettings.json

这是我的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 

相关内容