Huanshere / Huanshere/VideoLingo
NLTK import security check blocks startup on Linux (Python 3.10)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 18.5k
- Forks
- 2k
- Avg merge
- 7h 41m
- Merged PRs (30d)
- 12
Description
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:
-PandPYTHONSAFEPATHrequire 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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with st.py and verify that environment setup occurs before other imports. Reproduce with Python 3.10 by running Streamlit from a directory containing a .py file, then confirm the worker no longer fails when the NLTK security variable is set. Done means the described Linux startup and button/refresh flow works without the ImportError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100