8000 After reinstalling Python, pythontex don't work (macOS) · Issue #225 · gpoore/pythontex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

After reinstalling Python, pythontex don't work (macOS) #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
quark67 opened this issue Apr 17, 2025 · 4 comments
Open

After reinstalling Python, pythontex don't work (macOS) #225

quark67 opened this issue Apr 17, 2025 · 4 comments

Comments

@quark67
Copy link
quark67 commented Apr 17, 2025

I use this code:

\documentclass[11pt]{article}% 
\usepackage{pythontex} 
\usepackage{nopageno} 
\begin{document} 
\begin{pyconsole} 
x = 987.27 
x = x**2 
\end{pyconsole} 
 
The variable is $x=$ \pycon{x} 
\end{document}

With the previous installation the output is:

Image

It create some files:

Image

and a file test1.pytxcode.

With the new installation, I have this output:

Image

no folder pythontex-files-test10 but a file test10.pytxcode.

In the log from the compilation:

Package PythonTeX Warning: Non-existent console content on input line 8.


Package PythonTeX Warning: Missing autoprint content on input line 10.

The file test10.pytxcode contains this:

=>PYTHONTEX#pycon#default#default#0#console#####5#
x = 987.27
x = x**2
=>PYTHONTEX#pycon#default#default#1#i#####10#
x
=>PYTHONTEX:SETTINGS#
version=0.18
outputdir=pythontex-files-test10
workingdir=.
workingdirset=false
gobble=none
rerun=default
hashdependencies=default
makestderr=false
stderrfilename=full
keeptemps=none
pyfuture=default
pyconfuture=none
pygments=true
pygglobal=:GLOBAL||
fvextfile=-1
pyconbanner=none
pyconfilename=stdin
depythontex=false
pygfamily=py|python3|
pygfamily=pycon|pycon|
pygfamily=sympy|python3|
pygfamily=sympycon|pycon|
pygfamily=pylab|python3|
pygfamily=pylabcon|pycon|

The command python3 -m pip list in the terminal gives (among others):

Pygments 2.19.1

which python
python: aliased to python3
which python3
/usr/local/bin/python3
python --version
Python 3.13.3
pythontex
env: python: No such file or directory

Oh, strange... But:

which pythontex
/Library/TeX/texbin/pythontex

and I have all these files in TeXLive:

Image

I use the IDE Texpad (renamed Texifier, https://www.texifier.com)

It use this script file:

#!/bin/bash
# Texpad build (.tpbuild) file to use PythonTeX within Texpad
# NB this is to demonstrate pythontex only, it would need alterations to support bibliographies, indices, etc.



pdflatex -synctex=1 "$TEXPAD_ROOTFILE"
pythontex "$TEXPAD_ROOTFILE_NO_EXT"
pdflatex -synctex=1 "$TEXPAD_ROOTFILE"

Edit

If I try in the terminal (on a new file test11.tex):

pdflatex test11.tex works (This is pdfTeX, Version 3.141592653-2.6-1.40.26 ... Output written on test11.pdf (1 page, 32850 bytes). Transcript written on test11.log.)

But:

pythontex test11
env: python: No such file or directory

Why? echo $PATH gives:

/usr/local/bin: ... :/Library/Apple/usr/bin:/Library/TeX/texbin

I tryed this:

/Library/TeX/texbin/pythontex test11
env: python: No such file or directory

What happens?

I found these informations in a previous Terminal window (before reinstallation of Python):

pythontex --version
env: python: No such file or directory
python --version
zsh: command not found: python
python3 --version
Python 3.13.2
pythontex
env: python: No such file or directory
which python
python not found
sudo ln -sf /usr/local/bin/python3 /usr/local/bin/python
Password:
python
Python 3.13.2 (main, Feb  4 2025, 14:51:09) [Clang 16.0.0 (clang-1600.0.26.6)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> quit
pythontex
/usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex3.py:549: SyntaxWarning: invalid escape sequence '\s'

So after enter sudo ln -sf /usr/local/bin/python3 /usr/local/bin/python it was working? Perhaps, I don't recall.

But is it safe to use sudo ln -sf /usr/local/bin/python3 /usr/local/bin/python ? I have reinstalled Python because (perhaps after enter this last command), my Python IDE don't anymore warned me about syntax error in the editing mode.

I'm afraid the (very old) Python2 -> Python3 transition was a disaster, with the introducing of "python3" command. But anyway, the transition is what it is, we cannot change anything.

But what need the end users (that don't know a lot about python installation, but only need to use it as a tool) to do?

Can anyone help me?

@obtitus
Copy link
obtitus commented Apr 17, 2025

Does it work again if you replace pythontex with pythontex3? (Do you no longer need the symlink?)

Background:
https://github.com/gpoore/pythontex/blob/master/pythontex/pythontex.py#L1 starts with

#!/usr/bin/env python

which your system no longer has, and therefore fails with env: python: No such file or directory. As you mentioned, the python2 -> python3 transition was not great, but is now so long ago that I would not be to worried about leaving the symlink in-place, so that using python always calls python3. There are python packages that do this, i.e. for ubuntu: https://askubuntu.com/questions/1296790/python-is-python3-package-in-ubuntu-20-04-what-is-it-and-what-does-it-actually

When using https://github.com/gpoore/pythontex/blob/master/pythontex/pythontex3.py#L1 instead, it has:

#!/usr/bin/env python3

and so should not need the symlink.

If you want to manually specify the python executable to use, you can instead of pythontex use:

/usr/local/bin/python3 /usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex.py

Note: you will see a bunch of these warnings after python3.11:

549: SyntaxWarning: invalid escape sequence '\s'

these are just warnings and will/has been fixed.

@quark67
Copy link
Author
quark67 commented Apr 17, 2025

Does it work again if you replace pythontex with pythontex3?

In Terminal, I have:

pythontex3 test11
zsh: command not found: pythontex3

If you want to manually specify the python executable to use, you can instead of pythontex use:

/usr/local/bin/python3 /usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex.py

Thanks, in Terminal,

/usr/local/bin/python3 /usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex.py test11

works.

But is pythontex a binary or a py file?

I recall the script provided by the Texifier editor:

pdflatex -synctex=1 "$TEXPAD_ROOTFILE"
pythontex "$TEXPAD_ROOTFILE_NO_EXT"
pdflatex -synctex=1 "$TEXPAD_ROOTFILE"

And it worked previously (before reinstalling Python).

I'm not a Terminal nor Python geek.

All I ask is a working solution.

If I add a echo $PATH in the script:

echo $PATH
pdflatex -synctex=1 "$TEXPAD_ROOTFILE"
pythontex "$TEXPAD_ROOTFILE_NO_EXT"
pdflatex -synctex=1 "$TEXPAD_ROOTFILE"

I obtain this:

/bin/bash /Users/my_account/Library/Application Support/Texpad/BuildScripts/PythonTeX.tpbuild

/usr/bin:/bin:/usr/sbin:/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/Library/TeX/texbin
This is pdfTeX, Version 3.141592653-2.6-1.40.26
(etc.)

In the script, this don't work:

pdflatex -synctex=1 "$TEXPAD_ROOTFILE"
/usr/local/bin/python3 pythontex "$TEXPAD_ROOTFILE_NO_EXT"
pdflatex -synctex=1 "$TEXPAD_ROOTFILE"

With all complete paths:

pdflatex -synctex=1 "$TEXPAD_ROOTFILE"
/usr/local/bin/python3 /usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex.py "$TEXPAD_ROOTFILE_NO_EXT"
pdflatex -synctex=1 "$TEXPAD_ROOTFILE"

this works, but needs to be changed when the texlive year is updated.

And it worked previously with only pythontex "$TEXPAD_ROOTFILE_NO_EXT" (why only pythontex and not python pythontex? and not python pythontex.py?)

The pythontex (not pythontex.py) in /Library/TeX/texbin/pythontex is:

Image

Texbin is also an alias???

Image

I discover this yet (I thought it was a regular folder).

Image

So I tested python /Library/TeX/texbin/pythontex test11 in the Terminal and it works.

But in the script for Texifier, with:

pdflatex -synctex=1 "$TEXPAD_ROOTFILE"
python /Library/TeX/texbin/pythontex "$TEXPAD_ROOTFILE_NO_EXT"
pdflatex -synctex=1 "$TEXPAD_ROOTFILE"

I still obtain:

Image

test10.tex is tested on Texifier, test11.tex is tested on the Terminal:

Image

Between tests, I deleted all files except .tex.

@quark67
Copy link
Author
quark67 commented Apr 18, 2025

After a lot of tests, with the help of an AI (because I'm not a Python/Terminal expert), pythontex test11 don't work in the terminal because on macOS there is not python command but only a python3 command (installed with Homebrew). I have an alias python for python3 but this is a zsh alias, not a system alias. The shebang in pythontex(in /usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex.pyin fact) is #!/usr/bin/env python so with the command pythontex test11 in the terminal, the command python is searched but not found.

So one solution is to change in /usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex.py the shebang to #!/usr/bin/env python3 (as we are in 2025...). Yes this drop the support for Python 2.7, supported by pythontex, but useless for me (and probably for the majority of users).

After this change, in Terminal, pythontex test11 works!!!

And in Texifier, I need to use this:

pdflatex -synctex=1 "$TEXPAD_ROOTFILE"
/usr/local/bin/python3 /Library/TeX/texbin/pythontex "$TEXPAD_ROOTFILE_NO_EXT"
pdflatex -synctex=1 "$TEXPAD_ROOTFILE"

(/usr/local/bin/python3 because I use the Homebrew installation of Python).

Yet it is working. Thanks.

@quark67
Copy link
Author
quark67 commented Apr 19, 2025

Oh no, still not working!!!

The code (from https://clogique.fr/maths/profs/latex/doc/exemples_Pythontex.pdf):

\begin{pyverbatim}
xA = float(input(" Entrez xA ")
yA = float(input(" Entrez yA ")
xB = float(input(" Entrez xB ")
yB = float(input(" Entrez yB ")
if xA <> xB:
	a=(yB - yA) / (xB - xA)
	b=yA - a*xA
	print("La fonction affine dont la courbe est (AB) est")
	print("f(x) =",a, "*x+", b)
else :
	print("(AB) n'est pas la courbe d'une fonction affine.")
\end{pyverbatim}

is working.

Image

The code:

$2^{10} = \py{2**10}$

is not working.

Image

(was working in a previous compilation four days before).

The error is (compiled in Terminal):

multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex3.py", line 1569, in run_code
    proc = subprocess.Popen(exec_cmd, stdout=out_file, stderr=err_file)
  File "/usr/local/Cellar/python@3.13/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/subprocess.py", line 1039, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        pass_fds, cwd, env,
                        ^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
                        gid, gids, uid, umask,
                        ^^^^^^^^^^^^^^^^^^^^^^
                        start_new_session, process_group)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.13/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/subprocess.py", line 1969, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'python'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.13/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ~~~~^^^^^^^^^^^^^^^
  File "/usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex3.py", line 1583, in run_code
    proc = subprocess.Popen(exec_cmd_string, stdout=out_file, stderr=err_file)
  File "/usr/local/Cellar/python@3.13/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/subprocess.py", line 1039, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        pass_fds, cwd, env,
                        ^^^^^^^^^^^^^^^^^^^
    ...<5 lines>...
                        gid, gids, uid, umask,
                        ^^^^^^^^^^^^^^^^^^^^^^
                        start_new_session, process_group)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.13/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/subprocess.py", line 1969, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'cmd /C "@echo off & call python pythontex-files-test12/py_default_default.py & if errorlevel 1 exit 1"'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Library/TeX/texbin/pythontex", line 62, in <module>
    pythontex.main()
    ~~~~~~~~~~~~~~^^
  File "/usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex3.py", line 2828, in main
    do_multiprocessing(data, temp_data, old_data, engine_dict)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex3.py", line 1390, in do_multiprocessing
    result = task.get()
  File "/usr/local/Cellar/python@3.13/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/multiprocessing/pool.py", line 774, in get
    raise self._value
FileNotFoundError: [Errno 2] No such file or directory: 'cmd /C "@echo off & call python pythontex-files-test12/py_default_default.py & if errorlevel 1 exit 1"'

(recall: I have changed #!/usr/bin/env python to #!/usr/bin/env python3 in /usr/local/texlive/2024/texmf-dist/scripts/pythontex/pythontex.py because we are in 2025 and I don't have a python command, only a python3 command; I don't know if this was the reason).

I cannot create a symbolic link from python3 to python because this probably break another software.

What??? I read in the end line of the error: No such file or directory: 'cmd /C "@echo off & call python pythontex-files-test12/py_default_default.py & if errorlevel 1 exit 1"'

But is not cmd /C a windows command? I'm on a Mac!

Or was this because of & call python, as I don't have a python command?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0