Bug Description
On Linux, VideoLingo fails to start with the following error when the current working directory contains any .py file (or when Streamlit's subprocess workers inherit the parent process environment):
ImportError: Blocked import of regex from current working directory for security reasons.
File "videolingo/.venv/lib/python3.10/site-packages/nltk/inisec.py", line 128, in find_spec
raise ImportError(
f"Blocked import of {fullname} from current working directory "
"for security reasons. Use '-P' or set PYTHONSAFEPATH to prevent "
"Python from searching the current working directory."
)
Root Cause
NLTK v4.x added an import security hook (nltk/inisec.py) that blocks modules resolved from the current working directory when the import is initiated by NLTK or its dependencies (including g2p_en → nltk → regex).
The NLTK docs state:
-P and PYTHONSAFEPATH require Python 3.11+. On Python 3.10 they have no effect.
The NLTK hook itself exposes a workaround via environment variable (confirmed in nltk/inisec.py line 156):
if os.environ.get("NLTK_DISABLE_IMPORT_SECURITY") != "1":
_install()
However, os.environ.setdefault("PYTHONSAFEPATH", "1") on line 149 runs after the hook is installed, so setdefault cannot undo the check in the current interpreter — it's purely for child process inheritance.
Reproduction Steps
- Install VideoLingo on Linux with uv + Python 3.10
- Run:
streamlit run st.py
- Access the web UI — the page loads
- Click any button or refresh — the subprocess worker crashes with the error above
Workaround
Setting NLTK_DISABLE_IMPORT_SECURITY=1 in the environment before launching Streamlit works:
NLTK_DISABLE_IMPORT_SECURITY=1 streamlit run st.py
Suggested Fix
Add this at the very top of st.py (before any other imports):
import os
os.environ.setdefault("NLTK_DISABLE_IMPORT_SECURITY", "1")
Or document it prominently in the README for Linux/macOS users on Python 3.10.
Environment
- OS: Ubuntu 24.04 (Linux)
- Python: 3.10.19 (via uv)
- NLTK: bundled via requirements
- Streamlit: latest
- VideoLingo: 3.0.3
Bug Description
On Linux, VideoLingo fails to start with the following error when the current working directory contains any .py file (or when Streamlit's subprocess workers inherit the parent process environment):
Root Cause
NLTK v4.x added an import security hook (
nltk/inisec.py) that blocks modules resolved from the current working directory when the import is initiated by NLTK or its dependencies (includingg2p_en→nltk→regex).The NLTK docs state:
The NLTK hook itself exposes a workaround via environment variable (confirmed in
nltk/inisec.pyline 156):However,
os.environ.setdefault("PYTHONSAFEPATH", "1")on line 149 runs after the hook is installed, sosetdefaultcannot undo the check in the current interpreter — it's purely for child process inheritance.Reproduction Steps
streamlit run st.pyWorkaround
Setting
NLTK_DISABLE_IMPORT_SECURITY=1in the environment before launching Streamlit works:Suggested Fix
Add this at the very top of
st.py(before any other imports):Or document it prominently in the README for Linux/macOS users on Python 3.10.
Environment