Skip to content

"This environment is externally managed" when library tries to install package during runtime #13

@samrat

Description

@samrat

Hello, thanks for this library!

I'm trying to use a library which depends on spacy. This library seems to install a model as a Python package during runtime. And I get this error:

[notice] A new release of pip is available: 24.3.1 -> 25.0.1
[notice] To update, run: /Users/samrat/Library/Caches/pythonx/0.4.2/uv/0.5.21/python/cpython-3.12.8-macos-aarch64-none/bin/python -m pip install --upgrade pip
error: externally-managed-environment

× This environment is externally managed
╰─> This Python installation is managed by uv and should not be modified.

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.

This is the script I ran:

Mix.install([
  {:pythonx, "~> 0.4.2"}
])

Pythonx.uv_init("""
[project]
name = "project"
version = "0.0.0"
requires-python = "==3.12.*"
dependencies = [
  "misaki[en]",
]
""")

Pythonx.eval(
  """
  import spacy
  spacy.cli.download("en_core_web_trf")
  """,
  %{}
)

The equivalent Python script(also run using uv) seems to run fine:

#!/usr/bin/env python3
# /// script
# dependencies = [
#   "pip",
#   "misaki[en]"
# ]
# ///

import spacy
# Download spaCy model if needed
try:
    spacy.load("en_core_web_trf")
except OSError:
    print("Downloading en_core_web_trf...")
    spacy.cli.download("en_core_web_trf")
    print("Installed en_core_web_trf")

Any ideas on how I could get around this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions