improve: Prompt for venv creation before system install fallback
**Context:** PR #163 fixed critical venv detection bugs but used aggressive --break-system-packages flag as immediate fallback. **Improvement:** Now when no venv is found, the script: 1. Warns user about missing virtual environment 2. Offers to create one automatically (y/n prompt) 3. If yes: Creates venv, activates it, proceeds safely 4. If creation fails: Falls back to system install with warning 5. If no: Proceeds with system install but shows clear warning **Benefits:** - Encourages best practices (venv usage) - Less aggressive about bypassing system protections - Still supports system install when needed - Better user experience with clear choices **Backward Compatibility:** - All three original scenarios still work - Only adds new prompt in "no venv" scenario - Default behavior unchanged for existing venv users 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
26
setup_mcp.sh
26
setup_mcp.sh
@@ -46,8 +46,30 @@ elif [[ -d "venv" ]]; then
|
||||
source venv/bin/activate
|
||||
PIP_INSTALL_CMD="pip install"
|
||||
else
|
||||
echo "No virtual environment found. Using system pip with --user --break-system-packages flags"
|
||||
PIP_INSTALL_CMD="pip3 install --user --break-system-packages"
|
||||
echo -e "${YELLOW}⚠${NC} No virtual environment found"
|
||||
echo "It's recommended to use a virtual environment to avoid conflicts."
|
||||
echo ""
|
||||
read -p "Would you like to create one now? (y/n) " -n 1 -r
|
||||
echo ""
|
||||
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Creating virtual environment..."
|
||||
python3 -m venv venv || {
|
||||
echo -e "${RED}❌ Failed to create virtual environment${NC}"
|
||||
echo "Falling back to system install..."
|
||||
PIP_INSTALL_CMD="pip3 install --user --break-system-packages"
|
||||
}
|
||||
|
||||
if [[ -d "venv" ]]; then
|
||||
source venv/bin/activate
|
||||
PIP_INSTALL_CMD="pip install"
|
||||
echo -e "${GREEN}✓${NC} Virtual environment created and activated"
|
||||
fi
|
||||
else
|
||||
echo "Proceeding with system install (using --user --break-system-packages)..."
|
||||
echo -e "${YELLOW}Note:${NC} This may override system-managed packages"
|
||||
PIP_INSTALL_CMD="pip3 install --user --break-system-packages"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "This will install: mcp, requests, beautifulsoup4"
|
||||
|
||||
Reference in New Issue
Block a user