diff --git a/spacy/cli/download.py b/spacy/cli/download.py index 35afef609..7196b7fca 100644 --- a/spacy/cli/download.py +++ b/spacy/cli/download.py @@ -9,6 +9,7 @@ from .. import about from ..errors import OLD_MODEL_SHORTCUTS from ..util import ( get_minor_version, + is_in_interactive, is_in_jupyter, is_package, is_prerelease_version, @@ -95,6 +96,11 @@ def download( "You can do this clicking on the 'Restart Kernel' button (or " "'Restart Runtime' button in the case of Google Colab)" ) + elif is_in_interactive(): + reload_deps_msg = ( + f"{reload_deps_msg}This includes the current interactive Python session: " + "You can do this by pressing 'Ctrl+D' (or 'Ctrl+Z' and 'Enter' on Windows)." + ) msg.info( "Reloading dependencies", reload_deps_msg, diff --git a/spacy/util.py b/spacy/util.py index 79fcb8b8d..79c911491 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -43,11 +43,12 @@ import catalogue import langcodes import numpy import srsly -import thinc from catalogue import Registry, RegistryError from packaging.requirements import Requirement from packaging.specifiers import InvalidSpecifier, SpecifierSet from packaging.version import InvalidVersion, Version + +import thinc from thinc.api import ( Adam, Config, @@ -1111,6 +1112,15 @@ def is_in_jupyter() -> bool: return False +def is_in_interactive() -> bool: + """Check if user is running spaCy from an interactive Python + shell. Will return True in Jupyter notebooks too. + RETURNS (bool): True if in interactive mode, False if not. + """ + # https://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode + return hasattr(sys, "ps1") or hasattr(sys, "ps2") + + def get_object_name(obj: Any) -> str: """Get a human-readable name of a Python object, e.g. a pipeline component.