DevStack部署报错求助:执行./stack.sh时出现Python2.7(Django)错误
./stack.sh Hey there! Let's work through that Python 2.7/Django error you're hitting with DevStack's ./stack.sh script. This is a super common issue, especially since modern DevStack versions have fully moved to Python 3—here's how to fix it step by step:
1. Check Your DevStack Branch Compatibility
First off, most newer DevStack branches (like stable/ussuri and later) no longer support Python 2.7. If you're using an older branch (e.g., stable/queens or earlier), those do rely on Python 2, but they're no longer maintained (no security patches, bug fixes, etc.).
- To check your current branch:
git branch - If you can, switch to a Python 3-compatible branch:
git checkout stable/ussuri git submodule update --init
2. Force DevStack to Use Python 3
If you absolutely need to stick with your current branch (though I strongly advise against it for security reasons), you can override the Python version in your local.conf file:
- Edit
devstack/local.confand add these lines:USE_PYTHON3=True FORCE_PYTHON3=True
This tells DevStack to prioritize Python 3 for all dependency installs, so it won't pull in Python 2-specific Django versions.
3. Clean Up Old Python 2 Environment Residues
Leftover Python 2 packages or cached environments can mess up the installation. Let's wipe those out:
- Stop any running DevStack services:
./unstack.sh - Run the official cleanup script to remove old dependencies and virtual environments:
./clean.sh - If your system has
pip2installed, manually uninstall any Python 2 Django packages:sudo pip2 uninstall django -y
4. Set Python 3 as Your System Default
Make sure your system's default Python points to a 3.x version (not 2.7):
- Check your current default:
python --version - If it's still Python 2, use
update-alternativesto switch (adjust the path to your Python 3 version if needed):sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 sudo update-alternatives --config python
Select the Python 3 option when prompted.
5. (Last Resort) Match Django Version to Python 2
If you must use an old DevStack branch that requires Python 2, you'll need to install a Django version that supports Python 2 (the last one is Django 1.11.29):
- Create a custom requirements directory (e.g.,
~/devstack-custom-requirements) - Inside it, create a
global-requirements.txtfile with:django==1.11.29 - Edit
devstack/local.confto point to this directory:REQUIREMENTS_DIR=~/devstack-custom-requirements
A Quick Note of Caution
Using Python 2 or unsupported Django versions is a huge security risk—these haven't received security patches in years. If at all possible, upgrading to a modern, supported DevStack branch is the best long-term fix.
内容的提问来源于stack exchange,提问作者rania triki

