# python.sty on TeX Live 2013 - Forbidden to open for writing error

I have a fresh install of TeX Live 2013 and am attempting to compile a file using the python package. Here is the relevant portion of the file

\begin{python}
print 'hi'
\end{python}


I've compiled successfully on my linux machine with TeX Live 2013, but cannot get my windows 7 machine to compile successfully. When I run latex --shell-escape pytest.tex I get an error which begins with

pytest.py: Forbidden to open for writing
! I can't write on file pytest.py'.
\@python ...mediate \openout \@out =\@outname .py
\newlinechar ='15 \begingr...


Can anyone help me fix this so I can compile latex documents using python.sty on my windows machine?

# Update

So I'm pretty certain the issue has to do with permissions. If that is the case it would be really great if there were a few easy tests I could run to determine why \write18 cannot open files for writing / what it is trying to do. I've seen some problems from searching that were related to the TEXMFOUTPUT environment variable, but I don't know (1) what to set as the value of TEXMFOUTPUT in order to make sure that these temporary python files are created in the current working directory and (2) if setting TEXMFOUTPUT would have anything to do with these \write18 permission problems.

Ok, one new piece of information: So, I've created a minimal example:

\documentclass[letterpaper,10pt]{article}
\usepackage{python}
\begin{document}

\begin{python}
print 'hi'
\end{python}

\end{document}


When compiled after the ! I can't write on file pytest1.py' It says (Press Enter to retry, or Control-Z to exit; default file extension is '.tex' Is this error because write18 can only write to a .tex file?

At the beginning of the compile on the second line it just says  \write18 enabled'. So it is not running with restricted \write18. I feel like I am really close to fixing this.

# Solved

The comment python.sty on TeX Live 2013 - Forbidden to open for writing error was exactly right. I had .py listed in my PATHEXT environment variable. Removing it allowed the file to compile without error.

• This seems like a problem with permissions. Are you administrator on the machine? Are you running TeX from the command prompt, or from within an editor? Run either (cmd or your editor) as administrator and try again. – Werner Oct 29 '13 at 5:44
• On Windows systems you can't use \write to create any executable file types (.bat is the common one). Do you have .py set up to be associated with Pyhton and runnable? If so, you'll need to write to a different name then use write18 to rename to .py. – Joseph Wright Oct 29 '13 at 7:39
On Windows, TeX systems deliberately disable writing of executable file types (which are extension-based) via \write operations. Thus you cannot create a file called foo.py if .py files are set up to be executable. The common case for this problem is batch (.bat) files, which are plain text but executable without any add-ons and thus 'forbidden'. With \write18 enabled, the easiest approach is to write to an alternative file name then use use the shell escape to rename the file, which is allowed as \write18` is 'do whatever you want'.