I have two versions. How can I tell to pythontex the path to the Python3 to be used if it is possible ?
3 Answers
See the pythontex documentation (bottom of subsection 2.2 in v0.12?); it lists a number of options that pythontex.py accepts, including the following one, which allows you to specify the interpreter that pythontex should use:
--interpreterThis allows the interpreter for a given language to be specified. The argument should be in the form
--interpreter "<interpreter>:<command>, <interp>:<cmd>, ..."where
<interpreter>ispython,ruby, etc., and<command>is the command for invoking the desired interpreter. The argument to--interpretermay also be in the form of a Python dictionary. The argument need not be enclosed in quotation marks if it contains no spaces.For example, by default Python code is executed with whatever interpreter the
pythoncommand invokes. But Python 3 could be specified using--interpreter python:python3(many Linux distributions) or--interpreter "python:py -3"(Windows, with Python 3.3 installed so that the py wrapper is available).
-
Thanks. I really think that the documentation should put this in a dedicated section. – projetmbc Aug 23 '14 at 11:01
-
GPoore, the author of
pythontex, is active on TeX.SX. I'm sure he'll see your question and he might take your suggestion onboard for a future release. – jub0bs Aug 23 '14 at 11:06 -
-
4@projetmbc I've added a note about
--interpreterto the quickstart for the next release. – G. Poore Aug 23 '14 at 16:08 -
1
In the document The PythonTex package there is an explanation:
--interpreter python:python3
So I changed my sublime-build to:
"shell_cmd": "pdflatex $file_name && pythontex $file_name --interpreter python:python3 && pdflatex $file_name"
and it worked just fine.
I don't know, however, how to make \usepackage{python} use python3... It worked and suddenly started using python2...
- 155
I assume the OP wanted to use pythontex, but he had Python 2 and Python 3 installed. Under these circumstances, if you want to use Python 3 in your tex files, the --interpreter flag is supposed to work.
Alas, I could not get that --interpreter to work, and I nearly gave up.
Taking a closer look at the pythontex.py module, I noticed that it calls another module named pythontex3.py when it detects Python 3 is the default on your system.
So: you can tell your pythontex installation to use Python 3 by invoking pythontex3.py instead of pythontex.py when building your tex file.
On my system I found this module at:
/usr/local/texlive/2019/texmf-dist/scripts/pythontex/pythontex3.py
- 168
-
1Welcome to TEXSE, could you explain, how your answer solves OP's problem? – Raaja_is_at_topanswers.xyz Sep 11 '19 at 06:47
-
pythonthat are on your system, and what are the versions' numbers. – Mico Aug 23 '14 at 10:04