9

I have two versions. How can I tell to pythontex the path to the Python3 to be used if it is possible ?

projetmbc
  • 13,315
  • How do you do this with a non-TeX way? – percusse Aug 23 '14 at 09:02
  • 1
    Which operating system do you use, how did you install the various versions of python that are on your system, and what are the versions' numbers. – Mico Aug 23 '14 at 10:04
  • 1
    Typically, I use Anaconda with Python 3 and Python 2 is the standard one from my distribution. I work on all platforms : Mac O$, Windows and Lubuntu. – projetmbc Aug 23 '14 at 10:47

3 Answers3

7

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:

--interpreter

This allows the interpreter for a given language to be specified. The argument should be in the form

--interpreter "<interpreter>:<command>, <interp>:<cmd>, ..."

where <interpreter> is python, ruby, etc., and <command> is the command for invoking the desired interpreter. The argument to --interpreter may 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 python command 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).

jub0bs
  • 58,916
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...

khaz
  • 155
0

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

Willem
  • 168