3

When I try to compile the following file, test.tex, in an otherwise empty folder:

\documentclass[]{report}

\usepackage{python}

\begin{document}

\begin{python}
print(0)
\end{python}

\end{document}

I get the following error message:

! I can't write on file `test.py'.

What is the reason for this; why can't pdflatex write on that file?

I have tried to compile from the TeXstudio editor, as well as from Command Prompt and from Git Bash, both as my own user and in elevated mode as administrator, always getting the same error. I'm compiling with pdflatex.exe -synctex=1 -interaction=nonstopmode -shell-escape test.tex from the terminal, and with pdflatex.exe -synctex=1 -interaction=nonstopmode -shell-escape %.tex from TeXstudion, which should generate the same command. I'm using MiKTeX and Windows 10. My Python version is 3.5.3 and it is 64-bit.

Here is the entire log file, test.log:

This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6350 64-bit) (preloaded format=pdflatex 2017.7.26)  2 NOV 2017 17:19
entering extended mode
**./test.tex
(test.tex
LaTeX2e <2017-04-15>
Babel <3.10> and hyphenation patterns for 75 language(s) loaded.
("D:\Program Files\MiKTeX 2.9\tex\latex\base\report.cls"
Document Class: report 2014/09/29 v1.4h Standard LaTeX document class
("D:\Program Files\MiKTeX 2.9\tex\latex\base\size10.clo"
File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@chapter=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\c@figure=\count86
\c@table=\count87
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
("D:\Program Files\MiKTeX 2.9\tex\latex\python\python.sty"
Package: python 2007/06/07 v0.21 Python in LaTeX
\@out=\write3
\@module=\write4
)
No file test.aux.
\openout1 = `test.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
! I can't write on file `test.py'.
\@python ...mmediate \openout \@out =\jobname .py 
                                                  \newlinechar ='15 \begingr...
l.8 p
     rint(0)
Please type another output file name
! Emergency stop.
\@python ...mmediate \openout \@out =\jobname .py 
                                                  \newlinechar ='15 \begingr...
l.8 p
     rint(0)
*** (job aborted, file error in nonstop mode)


Here is how much of TeX's memory you used:
 231 strings out of 493323
 2485 string characters out of 3139054
 53648 words of memory out of 3000000
 3856 multiletter control sequences out of 15000+200000
 3640 words of font info for 14 fonts, out of 3000000 for 9000
 1141 hyphenation exceptions out of 8191
 23i,0n,17p,118b,36s stack positions out of 5000i,500n,10000p,200000b,50000s
!  ==> Fatal error occurred, no output PDF file produced!

Except from this log file, I also get a file called test.aux, but that's it. There is no file called test.py that is generated.

4
  • Do you already have a file test1.py in the targeted output directory? Is is marked (by Windows) as read-only?
    – user139954
    Commented Oct 29, 2017 at 15:01
  • I believe it should actually be called test1.py.out...
    – Alex
    Commented Oct 31, 2017 at 18:50
  • @RobtAll See my updated question. Seems like the error message involves test.py now instead of test1.py, perhaps because I moved the text file from a folder with other text files in it, and cleaned up some auxiliary files in the process. Commented Nov 2, 2017 at 16:36
  • @Alex Perhaps, but that's not what I'm getting in the error message. The the 1 seems to have disappeared, by the way. See my updated question. Commented Nov 2, 2017 at 16:37

1 Answer 1

6
+50

If pdflatex can't write the py file then the most probable cause is some protection software that denies it the rights. There has been some reports that e.g. bitdefender does this: pdflatex won't write in certain folders

But this is perhaps not the sole problem that you will get with the python package. It uses the program cat to write the files which normally doesn't exist in windows. I only could compile your file in a git bash.

Edit

I think I found the reason why on some systems the .py can not be written. On the one computer where it failed for me too .PY was in the PATHEXT variable:

 PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY

After I removed .PY (this needed admin rights) pdflatex compiled again and could write the .py-file.

9
  • If cat is the problem, perhaps GnuWin32 would help? The cat executable is in the CoreUtils package. See gnuwin32.sourceforge.net/packages.html
    – user139954
    Commented Oct 29, 2017 at 20:07
  • I have tried to compile this in Git bash too (where cat indeed exists) but I still get the same problem. Commented Oct 30, 2017 at 19:41
  • Well you naturally must solve the access denied problem first. Did you check if some virus protection prevents pdflatex from writing files? Commented Oct 30, 2017 at 20:11
  • No I haven't. I only use the built-in virus protection in Windows 10; do you think it might be preventing pdflatex from writing to test1.py, and how do I check whether it is, in that case? On the other hand, pdflatex can write other files, as I can compile a tex file that doesn't use the python package. Commented Oct 31, 2017 at 18:21
  • Hm. Is your problem description exact? You are saying that you are trying to compile test.tex and in the error message you are mentioning test1.py. Where is the 1 from? Are you compiling on the command line or in an editor? Commented Oct 31, 2017 at 23:08

You must log in to answer this question.

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