0

I am using pythontex to execute python code in latex. Since I have a large python code, I am trying to import the code using pycode ("\pyc{import code}"). The latex and python codes compile fine, but no sensible output is produced.

A minimal working example is:

\documentclass{article}
\usepackage{pythontex}

\begin{document}
\pyc{import test}
\end{document}

Note that, test is a python file ("test.py"), which has the following content:

print("hi")

Any suggestion on this would be highly helpful. Thanks in advance.

8
  • That works just fine here, after pdflatex - pythontex - pdflatex I get a PDF with hi. Commented Sep 26, 2017 at 13:13
  • Torbjorn, that worked on another machine (linux plataform) for me too, but I haven't still figured out where the issue is. Did you get it working on a Windows OS ?
    – Ashok
    Commented Sep 26, 2017 at 16:16
  • No, Linux. By the way, does "no sensible output" mean "no output at all", or do you get some output, only it isn't sensible? Commented Sep 26, 2017 at 16:20
  • The output.pdf does not contain imported python code, whereas everything outside the imported python code is printed correctly.
    – Ashok
    Commented Sep 26, 2017 at 17:15
  • Code? It's not supposed to print the code. The manual says of \pyc: "\pyc[<session>]<openingdelim><code><closing delim> This command is used for executing but not typesetting <code>. The suffix c is an abbreviation of code. If the print statement/function is used within <code>, printed content will be included automatically so long as the package autoprint option is set to true (the default setting)." Commented Sep 26, 2017 at 17:24

1 Answer 1

2

This issue is caused by a file name conflict. In this case, both the .tex file and the .py file have the same name (which is "test"). Renaming either one of them will solve the issue.

It is interesting to note that, only the Windows OS has this issue; everything runs fine in Linux, even if the file names are the same.

2
  • Good to know, I was about to do the same thing and happened to stumble upon this question! Commented Sep 27, 2017 at 10:14
  • 1
    JiyuuSensei, nice to hear that this answer helped you. Also make sure that you are assigning path variables correctly. Seems like python and tex do not blend well in Windows OS (by default).
    – Ashok
    Commented Sep 27, 2017 at 10:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .