Getting PythonTex to work with TexStudio
After trying lots of things, including the suggestions from here, I have found just one solution to solving the Qt issue: start TexStudio from the Anaconda prompt
Even though the environment variables are the same (can check using os.environ
in python and easily print output to LaTeX file using the pyconsole
environment), this seems to work. Presumably there is a different 'priority' given to paths in the environment?
EDIT
I dug into this a bit further to try and understand why this works. Using !set
from a python prompt reveals the environment variables currently active. Looking at the PATH
variable, it can be seen that Anaconda adds its paths to the top of the path list (even though they are already further down the list as inhereited from the system environment variables). So the order of the environment variables matters as the environment will stop at the first instance of whatever command it is looking for. So the fix is to put the Anaconda paths to the top of my environment variables. This means I can run TexStudio from the usual shortcut and the correct paths are used!
Related videos on Youtube
Colin
Professor in Civil Engineering, expertise in structural dynamics and probabilistic methods for structures.
Updated on August 01, 2022Comments
-
Colin over 1 year
I cannot get PythonTex to fully work with TexStudio. I'm having a nightmare with this and solved many issues, including activating the conda base, mkl-service library clashes, and TexStudio command paths. My environment variables also needed to be fixed to include the Anaconda library binaries in the search path. The remaining issue I cannot solve after two days is generating plots through PythonTex. The error appears as: "This application failed to start because it could not find or load Qt platform plugin"windows". A native Windows cmd has the same problem so I do not think PythonTex is at fault. I think the problem is with importing libraries outside of the python core into TexStudio.
Here is a MWE
\documentclass{article} \usepackage{pythontex} \begin{document} \begin{pycode} import sys print(sys.version) \end{pycode} \end{document}
This prints:
3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]
Here is a nonworking example
\documentclass{article} \usepackage{pythontex} \begin{document} \begin{pylabblock} rc('text', usetex=True) rc('font', family='serif') rc('font', size=10.0) rc('legend', fontsize=10.0) rc('font', weight='normal') x = linspace(0, 10) figure(figsize=(4, 2.5)) plot(x, sin(x), label='$\sin(x)$') xlabel(r'$x\mathrm{-axis}$') ylabel(r'$y\mathrm{-axis}$') legend(loc='lower right') savefig('myplot.pdf', bbox_inches='tight') \end{pylabblock} \end{document}
I have done the following to try and rectify the problem:
- Activated conda base
- Did
conda install mkl-service
- Tried piping conda activation as per this question
- Verified that there is no clash of MKL libraries using
where libiomp5md.dll
as indicated here and here - Verified the python code in Spyder and in the native cmd prompt
- Tried adding the QT_PLUGIN_PATH environment variable
Unfortunately, the solution here has not worked for me either. Any help much appreciated.
System:
- Windows10
- TexStudio 2.12.6
- Conda 4.8.2
- PythonTex 0.17
-
Tomáš Kruliš over 3 yearsHaving so much trouble with it as you do, I would recommend to move to use TeXworks and drop
Anaconda
distribution and use pure python (and install packages withpip
). I found no benefit for using Anaconda over python itself ... You example works for my setting on Win10, TeXworks in TeXlive2019, python 3.8 64bit and PythonTeX 0.17 -
Colin over 3 years@TomášKruliš I had been outside
conda
before, but needed pymc3 which is a nightmare of dependencies - the great strength ofconda
. Shouldn't this just work?! -
Tomáš Kruliš over 3 yearsYes, it certainly should. I am not that proficient in python (beginner programmer, I only dare to say). As not that pro, I dont se any nightmares - not using
pymc3
, I am using almost all its listed dependencies (except forTheano
) and I have no problem. For me is a surprise, that you have to set-up an envinment variable (?connected toqt
?) to make work a machine learning module. Doesnt seem right. I dare to say thatconda
has its own problems with dependencies managing, think I read somewhere it has trouble to keep up.