diff --git a/cyberpanel.sh b/cyberpanel.sh index 4a93694f5..0e55e2bed 100644 --- a/cyberpanel.sh +++ b/cyberpanel.sh @@ -1366,7 +1366,20 @@ export LC_CTYPE=en_US.UTF-8 export LC_ALL=en_US.UTF-8 #need to set lang to address some pip module installation issue. -Retry_Command "pip install --default-timeout=3600 virtualenv" +# Install virtualenv - handle Ubuntu 24.04's externally-managed-environment policy +if [[ "$Server_OS" = "Ubuntu" ]]; then + if [[ "$Server_OS_Version" = "24" ]]; then + # Ubuntu 24.04 has python3-venv by default, no need to install virtualenv + echo -e "Ubuntu 24.04 detected - using built-in python3-venv" + else + # For older Ubuntu versions, install virtualenv via apt + Retry_Command "DEBIAN_FRONTEND=noninteractive apt-get update" + Retry_Command "DEBIAN_FRONTEND=noninteractive apt-get install -y python3-virtualenv" + fi +else + # For non-Ubuntu systems, use pip (may need --break-system-packages on newer systems) + Retry_Command "pip install --default-timeout=3600 virtualenv" +fi Download_Requirement @@ -1381,8 +1394,13 @@ if [[ "$Server_OS" = "Ubuntu" ]] && ([[ "$Server_OS_Version" = "22" ]] || [[ "$S echo -e "Virtual environment created successfully" else echo -e "python3 -m venv failed, trying virtualenv..." - # Ensure virtualenv is properly installed - pip3 install --upgrade virtualenv + # For Ubuntu 24.04, python3-venv should work, but if not, try apt install + if [[ "$Server_OS_Version" = "24" ]]; then + Retry_Command "DEBIAN_FRONTEND=noninteractive apt-get install -y python3-venv" + else + # For Ubuntu 22.04, install virtualenv via apt + Retry_Command "DEBIAN_FRONTEND=noninteractive apt-get install -y python3-virtualenv" + fi virtualenv -p /usr/bin/python3 /usr/local/CyberPanel fi else diff --git a/cyberpanel_upgrade.sh b/cyberpanel_upgrade.sh index e4bf3b97b..8c340f7aa 100644 --- a/cyberpanel_upgrade.sh +++ b/cyberpanel_upgrade.sh @@ -505,12 +505,18 @@ elif [[ "$Server_OS" = "Ubuntu" ]] ; then DEBIAN_FRONTEND=noninteractive apt install -y build-essential libssl-dev libffi-dev python3-dev DEBIAN_FRONTEND=noninteractive apt install -y python3-venv - ### fix for pip issue on ubuntu 22 + ### fix for pip issue on ubuntu 22 and 24 apt-get remove --purge virtualenv -y - pip uninstall -y virtualenv - rm -rf /usr/lib/python3/dist-packages/virtualenv* - pip3 install --upgrade virtualenv + # Handle Ubuntu 24.04's externally-managed-environment policy + if [[ "$Server_OS_Version" = "24" ]]; then + echo -e "Ubuntu 24.04 detected - using apt for virtualenv installation" + DEBIAN_FRONTEND=noninteractive apt-get install -y python3-virtualenv + else + pip uninstall -y virtualenv 2>/dev/null || true + rm -rf /usr/lib/python3/dist-packages/virtualenv* + pip3 install --upgrade virtualenv + fi if [[ "$Server_OS_Version" = "18" ]] ; then @@ -652,14 +658,20 @@ if [ "$Server_OS" = "Ubuntu" ]; then echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Preparing Ubuntu environment for virtualenv..." | tee -a /var/log/cyberpanel_upgrade_debug.log rm -rf /usr/local/CyberPanel - # For Ubuntu 22.04, ensure we have the latest virtualenv that's compatible - if [[ "$Server_OS_Version" = "22" ]]; then - echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Ubuntu 22.04: Installing/upgrading virtualenv with proper dependencies..." | tee -a /var/log/cyberpanel_upgrade_debug.log - # Remove system virtualenv if it exists to avoid conflicts - apt remove -y python3-virtualenv 2>/dev/null || true - # Install latest virtualenv via pip - pip3 install --upgrade pip setuptools wheel - pip3 install --upgrade virtualenv + # For Ubuntu 22.04 and 24.04, handle virtualenv installation properly + if [[ "$Server_OS_Version" = "22" ]] || [[ "$Server_OS_Version" = "24" ]]; then + if [[ "$Server_OS_Version" = "24" ]]; then + echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Ubuntu 24.04: Using apt for virtualenv installation (externally-managed-environment policy)..." | tee -a /var/log/cyberpanel_upgrade_debug.log + # Ubuntu 24.04 has externally-managed-environment, use apt + DEBIAN_FRONTEND=noninteractive apt-get install -y python3-virtualenv + else + echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Ubuntu 22.04: Installing/upgrading virtualenv with proper dependencies..." | tee -a /var/log/cyberpanel_upgrade_debug.log + # Remove system virtualenv if it exists to avoid conflicts + apt remove -y python3-virtualenv 2>/dev/null || true + # Install latest virtualenv via pip + pip3 install --upgrade pip setuptools wheel + pip3 install --upgrade virtualenv + fi else pip3 install --upgrade virtualenv fi diff --git a/install/install.py b/install/install.py index f0be3d2dc..5c395697e 100644 --- a/install/install.py +++ b/install/install.py @@ -2039,16 +2039,26 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout'; latest = getVersion.json() except BaseException as msg: - command = "pip uninstall --yes urllib3" + # Handle Ubuntu 24.04's externally-managed-environment policy + pip_flags = "" + if self.distro == ubuntu: + try: + release = install_utils.get_Ubuntu_release(use_print=False, exit_on_error=False) + if release and release >= 24.04: + pip_flags = " --break-system-packages" + except: + pass # If version detection fails, try without flags + + command = f"pip uninstall --yes{pip_flags} urllib3" preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - command = "pip uninstall --yes requests" + command = f"pip uninstall --yes{pip_flags} requests" preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - command = "pip install http://mirror.cyberpanel.net/urllib3-1.22.tar.gz" + command = f"pip install{pip_flags} http://mirror.cyberpanel.net/urllib3-1.22.tar.gz" preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) - command = "pip install http://mirror.cyberpanel.net/requests-2.18.4.tar.gz" + command = f"pip install{pip_flags} http://mirror.cyberpanel.net/requests-2.18.4.tar.gz" preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) def installation_successfull(self):