Skip to content
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

Running pythontex in a virtual environment #3838

Open
sehHeiden opened this issue Jan 2, 2025 · 5 comments
Open

Running pythontex in a virtual environment #3838

sehHeiden opened this issue Jan 2, 2025 · 5 comments
Labels
enhancement New feature or (non bug related) change to the program.

Comments

@sehHeiden
Copy link

Type of JetBrains IDE (IntelliJ, PyCharm, etc.) and version

PyCharm

Operating System

Linux

TeXiFy IDEA version

0.9.9

What I did (steps to reproduce)

Added pythontex as external tool in before launch.

So my before lauch looks like:

  1. run the old automatic created steps
  2. run pythontex

Minimal example to reproduce the problem

\documentclass{article}
\usepackage{pythontex}

\begin{document}
\begin{pycode}
"""Show Graphs for Statistic of MaStR."""
print("Hallo")
\end{pycode}
\end{document}

Expected behavior

This behaviour works from the PyCharm terminal. Here the python version is: Python 3.12.6

  1. pdflatex
  2. pythontex
  3. pdflatex

Actual behavior

Get the error below.
Altough I have a .venv that works, has the correct python version as in the .python-version file.
Looks for me, that not the correct python python is used?

(if applicable) The full stacktrace of the exception thrown

  pyenv: version `3.12.6' is not installed (set by /home/.../.python-version)
@sehHeiden sehHeiden added bug Deficiencies in TeXiFy behaviour. untriaged Issue type still needs to be triaged or verified. labels Jan 2, 2025
@sehHeiden
Copy link
Author

I added an init.py file to the out folder and the folder of the latex files.

Not changing the error.

@sehHeiden
Copy link
Author

Do I have to activate the .venv for the external tools (not needed in the terminal).

I tried:

uv run pythontex

Not changing the error.

@PHPirates
Copy link
Collaborator

Thanks for the question, indeed in the current External LaTeX tool run configuration the command is hardcoded and will be run outside the virtual environment. Could you try with a regular external tool, and then activate the virtual environment there? For example, source .venv/Scripts/activate && pythontex main

(I think this functionality did not exist at the time I created the external tool run config, maybe it is obsolete now)

@PHPirates PHPirates added enhancement New feature or (non bug related) change to the program. and removed bug Deficiencies in TeXiFy behaviour. untriaged Issue type still needs to be triaged or verified. labels Jan 8, 2025
@PHPirates PHPirates changed the title Python version not found when using uv Running pythontex in a virtual environment Jan 8, 2025
@sehHeiden
Copy link
Author

What I tried is to write a bash script, that that sources the environment first and then executed pythontex.
That did work, but need to be handled slightly differently on win.

@PHPirates
Copy link
Collaborator

I just realised that just using a 'before launch' tool may not quite fix it, because you need to run LaTeX - pythontex - LaTeX. I think the best solution is to add environment variables to the External Tool run configuration, then you would be able to edit PATH so that pythontex will pick up the correct python executable.
Until then, I don't see an easier workaround than indeed such a bash script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or (non bug related) change to the program.
Projects
None yet
Development

No branches or pull requests

2 participants