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

Configuration broken when pandoc is not in the PATH #72

Open
moss-xyz opened this issue Dec 16, 2024 · 10 comments
Open

Configuration broken when pandoc is not in the PATH #72

moss-xyz opened this issue Dec 16, 2024 · 10 comments
Assignees
Labels

Comments

@moss-xyz
Copy link

Bit of an odd one here, didn't see anyone else with a similar issue that had been posted.

I seem to be able to import the python package, but unable to use it, meaning that the following fails:

import pandoc

text = "Hello world!"

p = pandoc.read(text)

It generates the following exception (CommandNotFound):

plumbum.commands.processes.CommandNotFound: (CommandNotFound(...), 'pandoc', [<LocalPath C:\WINDOWS\system32>, <LocalPath C:\WINDOWS>, <LocalPath C:\WINDOWS\System32\Wbem>, <LocalPath C:\WINDOWS\System32\WindowsPowerShell\v1.0>, <LocalPath C:\WINDOWS\System32\OpenSSH>, ... (list of PATHs)]

Which in turns triggers the following error:

RuntimeError: cannot find the pandoc program.
paths:['C:\\WINDOWS\\system32', 'C:\\WINDOWS', 'C:\\WINDOWS\\System32\\Wbem', 'C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0', 'C:\\WINDOWS\\System32\\OpenSSH', ... (list of PATHs)]

I would have thought the solution to this was to specify the path to pandoc.exe with pandoc.configure(), but that doesn't work either:

pandoc.configure("path/to/pandoc.exe") # same error

Is pandoc expected to be in my PATH? I installed it from conda using the instructions in the documentation, so not sure why this error is happening. I also tried to install an older version (3.2.1) with conda but it didn't work either.

@boisgera
Copy link
Owner

Hi @moss-xyz ,

No, pandoc does not need to be in your PATH (even if it makes things simpler).

Try pandoc.configure(path="path/to/pandoc.exe") or pandoc.configure(False, "path/to/pandoc.exe").

The path is not the first but the second argument in configure (the first being "auto").

Makes me wonder if I should make this configure function keyword arguments only ...

Cheers,

Sébastien

@moss-xyz
Copy link
Author

Hi @boisgera - apologies for the omission in my original post above, I had actually been using a keyword argument:

pandoc.configure(path="path/to/conda/env/Library/bin/pandoc.exe")

Per my psuedo-path above, pandoc seems to have been installed to /Library/bin/pandoc.exe, but the same error is cropping up even when I explicitly direct the script to it.

Weirdly, pandoc as a CLI seems to work! I was able to use it to successfully convert some markdown files to epubs last night. So it is definitely installed on my computer...

@boisgera
Copy link
Owner

Ah, too bad, that would have been an easy fix ...

AFAICT, the error you have can only happen when the configuration flag auto is set to True (precisely here).

That's pretty weird ... except if you have triggered an automatic configuration before you explicitly configure the path.

For example,

import pandoc
import pandoc.types 

pandoc.configure(path="...")

would fail at import pandoc.types since the types hierarchy is generated at runtime and needs to know what version of pandoc you are using (and therefore, calls implicitly pandoc.configure(auto=True) unless you have already configured pandoc manually).

Do you still have the error if all you do is

import pandoc
pandoc.configure(path="...")

?

@moss-xyz
Copy link
Author

Yes - just running import pandoc followed by pandoc.configure(path="...") triggers the issue. I wasn't previously importing pandoc.types (did not think it was necessary?), but trying to import that triggers the same error as pandoc.configure(path="..."), which is the same error from the OP, as I say above.

@boisgera
Copy link
Owner

Can you invoke your pandoc executable via plumbum?

For example, my executable is located at "/home/boisgera/.pixi/bin/pandoc" and I can do:

>>> import plumbum
>>> p = plumbum.local["/home/boisgera/.pixi/bin/pandoc"]
>>> print(p("--version"))
pandoc 3.2
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: /home/boisgera/.local/share/pandoc
Copyright (C) 2006-2024 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

@moss-xyz
Copy link
Author

Fascinating! That does seem to work?

>>> import plumbum
>>> p = plumbum.local["path/to/env/Library/bin/pandoc.exe"]
>>> print(p("--version"))
pandoc.exe 3.2.1
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: C:\Users\my-name\AppData\Roaming\pandoc
Copyright (C) 2006-2024 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

Curious what this will tell you

@boisgera
Copy link
Owner

Well, AFAICT the issue is not that the executable is not available through plumbum when you give it the proper path, but for some reason configure believes that you at requesting auto = True and then searches for pandoc in your PATH environnement variable and then fails to find it.

Unfortunately, I don't have access to Windows (not even via VirtualBox because of ongoing technical issues at Microsoft).

Are you by any chance able to use a debugger to go step by step and see if we are executing the auto=True branch and why?

@boisgera
Copy link
Owner

Unfortunately, I don't have access to Windows (not even via VirtualBox because of ongoing technical issues at Microsoft).

Are you by any chance able to use a debugger to go step by step and see if we are executing the auto=True branch and why?

Nevermind, I can reproduce on Linux, I'll deal with this. Thanks for your feedback!

@moss-xyz
Copy link
Author

Ah, great, let me know!

I've actually never used a debugger before but I had just gotten it set up and was stepping through the functions - very cool feature!

@boisgera boisgera self-assigned this Dec 24, 2024
@boisgera boisgera added the bug label Dec 24, 2024
@boisgera
Copy link
Owner

There is a faulty logic here where we import types before we update the configuration. That's an issue since the import triggers a configuration with auto=True if the _configuration is still None.

    if not read_only:  # set the configuration, update pandoc.types

        try:
            from . import types
        except ImportError:  # only sensible explanation:
            # the types module is actually being imported (interpreted)
            # and is calling configure.
            types = sys.modules["pandoc.types"]

        _configuration = {
            "auto": auto,
            "path": path,
            "version": version,
            "pandoc_types_version": pandoc_types_version,
        }

        types.make_types()

The code in types.py also has an issue. AFAICT if the configuration is defined, there is no need to recall configure.

_configuration = pandoc.configure(read=True)
if _configuration is None:
    pandoc.configure(auto=True)
else:
    pandoc.configure(**_configuration)

@boisgera boisgera changed the title Difficulty Importing/Using Pandoc Configuration broken pandoc is not in the PATH Dec 25, 2024
@boisgera boisgera changed the title Configuration broken pandoc is not in the PATH Configuration broken when pandoc is not in the PATH Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants