veneres / py-pandoc-include-code

Python filter for pandoc to replace the original pandoc-include-code that is no longer supported (https://github.com/owickstrom/pandoc-include-code)
MIT License
2 stars 1 forks source link

Cannot install the plugin #1

Open jermp opened 2 months ago

jermp commented 2 months ago

Hello, when trying to install the plugin under Python 3.12.4 , I get the following:

error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.

    If you wish to install a Python library that isn't in Homebrew,
    use a virtual environment:

    python3 -m venv path/to/venv
    source path/to/venv/bin/activate
    python3 -m pip install xyz

    If you wish to install a Python application that isn't in Homebrew,
    it may be easiest to use 'pipx install xyz', which will manage a
    virtual environment for you. You can install pipx with

    brew install pipx

    You may restore the old behavior of pip by passing
    the '--break-system-packages' flag to pip, or by adding
    'break-system-packages = true' to your pip.conf file. The latter
    will permanently disable this error.

    If you disable this error, we STRONGLY recommend that you additionally
    pass the '--user' flag to pip, or set 'user = true' in your pip.conf
    file. Failure to do this can result in a broken Homebrew installation.

    Read more about this behavior here: <https://peps.python.org/pep-0668/>

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

I tried with both:

pip install git+https://github.com/veneres/py-pandoc-include-code.git 
pip3 install git+https://github.com/veneres/py-pandoc-include-code.git 

but no luck so far. I'm running Mac OS X.

veneres commented 2 months ago

Hi @jermp, I assume the problem is related to the fact that the installation script also installs a command system-wide (py-pandoc-include-code). I quote a part of the PEP 668 Python specification mentioned in your error message:

First, it proposes a way for distributors of a Python interpreter to mark that interpreter as having its packages managed by means external to Python, such that Python-specific tools like pip should not change the installed packages in the interpreter’s global sys.path in any way (add, upgrade/downgrade, or remove) unless specifically overridden. It also provides a means for the distributor to indicate how to use a virtual environment as an alternative.

This is an opt-in mechanism: by default, the Python interpreter compiled from upstream sources will not be so marked, and so running pip install with a self-compiled interpreter, or with a distro that has not explicitly marked its interpreter, will work as it always has worked.

Second, it sets the rule that when installing packages to an interpreter’s global context (either to an unmarked interpreter, or if overriding the marking), Python-specific package managers should modify or delete files only within the directories of the sysconfig scheme in which they would create files. This permits a distributor of a Python interpreter to set up two directories, one for its own managed packages, and one for unmanaged packages installed by the end user, and ensure that installing unmanaged packages will not delete (or overwrite) files owned by the external package manager.

I thus assume that installing a command system-wide breaks this rule. I was able to replicate your error message by using the default python installation without any virtual environment.

Simple solution? Just use a virtual environment following this guide, or using conda, that I kindly suggest, following this guide.