Why Does Python Become Unresponsive When I Use Latex To Render Text?
Solution 1:
Note that pyplot.show()
blocks until you close the window.
If you are generating plots for your LaTeX documents, just remove pyplot.show()
.
Make sure that Python can actually findlatex
, dvipng
and gs
. (I would expect you to get a error message if that is not the case, but I haven't used python/matplotlib on ms-windows, so I'm not sure.) That is, their location should be in your PATH
environment variable. See the matplotlib documentation on environment variables.
Try the following in an interactive Python session:
>>> import subprocess
>>> subprocess.call(['latex', '--version'])
pdfTeX 3.14159265-2.6-1.40.17 (TeX Live 2016)
kpathsea version 6.2.2
Copyright 2016Han The Thanh (pdfTeX) et al.
There is NO warranty. Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.21; using libpng 1.6.21
Compiled with zlib 1.2.8; using zlib 1.2.8
Compiled with xpdf version 3.040
The stuff about the TeX version might well be different; it depends on which version of which TeX distribution you're using.
Most important is the last line; this is the return value of subprocess.call
and should be 0, indicating that the command return no error.
If the subprocess.call
raises an exception (like below; not sure if it will be the same on ms-windows), you need to modify the PATH
so that python can find LaTeX and the other things it needs.
>>> subprocess.call(['foo', '--version'])
Traceback (most recent calllast):
File "<stdin>", line 1, in<module>
File "/usr/local/lib/python2.7/subprocess.py", line 168, incallreturn Popen(*popenargs, **kwargs).wait()
File "/usr/local/lib/python2.7/subprocess.py", line 390, in __init__
errread, errwrite)
File "/usr/local/lib/python2.7/subprocess.py", line 1024, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Edit: If this is not the problem, it could be that is it TeX that is not quitting. Try running the script. When you get the error dialog, look in the task manager if there is still a (la)tex process running. Look at the LaTeX code that you use, and try running it in LaTeX to check that it is actually valid. It might get hung on an error...
Post a Comment for "Why Does Python Become Unresponsive When I Use Latex To Render Text?"