LaurentRDC / pandoc-plot

Render and include figures in Pandoc documents using your plotting toolkit of choice
https://laurentrdc.github.io/pandoc-plot/
GNU General Public License v2.0
216 stars 8 forks source link

Full path to executable being ignored #46

Closed MageJohn closed 2 years ago

MageJohn commented 2 years ago

I'm trying to configure the python executable for running matplotlib to one in a virtual environment. I need to do this to have access to all the installed packages there. Unfortunately pandoc-plot seems to ignore the setting and still runs the system version of python.

Specifically I have a source script that looks something like the following, where some_package is a package installed only in the venv:

```{.matplotlib executable="/full/path/to/venv/bin/python"}
import sys
print(f"sys.executable={sys.executable}", file=sys.stderr)
import some_package

With this in a markdown file and converting it with pandoc + pandoc-plot, pandoc-plot would give something like following:

[pandoc-plot] ERROR | Running command [pandoc-plot] ERROR | python "/tmp/pandocplot4826263390304275862.py" [pandoc-plot] ERROR | ended with exit code ExitFailure 1 [pandoc-plot] ERROR | [pandoc-plot] ERROR | sys.executable=/usr/bin/python [pandoc-plot] ERROR | Traceback (most recent call last): [pandoc-plot] ERROR | File "/tmp/pandocplot4826263390304275862.py", line 9, in [pandoc-plot] ERROR | import some_package [pandoc-plot] ERROR | ModuleNotFoundError: No module named 'some_package' [pandoc-plot] ERROR | [pandoc-plot] ERROR | [pandoc-plot] ERROR | Command "python "/tmp/pandocplot4826263390304275862.py"" failed with exit code 1. The script source was: [pandoc-plot] ERROR | [pandoc-plot] ERROR | 1 > import sys [pandoc-plot] ERROR | 2 > print(f"sys.executable={sys.executable}", file=sys.stderr) [pandoc-plot] ERROR | 3 > import some_package [pandoc-plot] ERROR |



Note that running the venv version of python directly and executing the above script works as expected: it prints the path to the virtual environment's executable (i.e '/full/path/to/venv/bin/python') and correctly imports the package.

I experimented with not setting the executable at all, and noticed that pandoc-plot seems to default to using the `python3` executable. That means that my configuration is being read, but the absolute path is being lost somewhere.
LaurentRDC commented 2 years ago

Thank you for your report! Let me take a look

LaurentRDC commented 2 years ago

I found the problem, and it is right here. In the expression Executable _ exename, the directory is ignored (_).

I'll try to patch this tonight

LaurentRDC commented 2 years ago

In the meantime, you can specify the absolute path to the executable in the .pandoc-plot.yml config file like so:

#.pandoc-plot.yml in the same directory where you are running `pandoc` and `pandoc-plot`
matplotlib:
  executable: /full/path/to/venv/bin/python

I've tested that this works

MageJohn commented 2 years ago

That's strange, it was actually using the configuration file that I first noticed the problem. I didn't mention it earlier because I was trying to provide a minimal description of the issue, and I didn't think the configuration file would make a difference.

I'll try again however, I might have missed something.

Update: for me there's no difference from using the config file, even when I carefully set it up just like your comment. I can tell that the file is being read, because the executable changes from python3 to just python again, but the absolute path is still being lost.

LaurentRDC commented 2 years ago

You are right, it works now with the config file only because I've fixed this. Stay tuned for the global fix

LaurentRDC commented 2 years ago

A fix has been merged into master. I'm preparing a release for tonight

MageJohn commented 2 years ago

That's amazing, thank you!

LaurentRDC commented 2 years ago

You are most welcome. Don't hesitate to raise other issues if you encounter other problems.