Skip to content

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

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

Closed
samrat opened this issue Feb 28, 2025 · 1 comment

Comments

@samrat
Copy link

samrat commented Feb 28, 2025

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?

@jonatanklosko
Copy link
Member

Hey @samrat! Thanks for the report, it should now work on main (#14, #15).

Note that you need to add pip to the dependency list, as you did in the latter script :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants