Django+Celery+Redis注册系统报错及pip导入dist失败求助
Hey there, sorry to hear you're stuck dealing with these frustrating errors—let's work through them one by one to get your system back on track.
First: Fix the Broken pip and distutils Import Error
Your pip is failing because the distutils module is corrupted or missing in your virtual environment. Here are two reliable approaches to fix this:
Option 1: Repair System-Wide distutils for Python 3.6
Since you're using Python 3.6.3, install the system-level distutils package that matches your Python version:
- For Debian/Ubuntu-based systems:
sudo apt-get install python3.6-distutils - For CentOS/RHEL-based systems:
sudo yum install python36-distutils
After installing, reactivate your virtual environment and test pip:
source /home/chhuti/projects/venv/chhuti/bin/activate pip --version
Option 2: Rebuild Your Virtual Environment
If repairing distutils doesn't resolve the issue, your virtual environment might be corrupted. Let's start fresh:
- Backup your dependencies (if you have a
requirements.txtfile, skip this step; otherwise, you can list installed packages manually from/home/chhuti/projects/venv/chhuti/lib/python3.6/site-packages/) - Delete the broken virtual environment:
rm -rf /home/chhuti/projects/venv/chhuti - Create a new virtual environment with Python 3.6:
python3.6 -m venv /home/chhuti/projects/venv/chhuti - Activate it and upgrade pip immediately:
source /home/chhuti/projects/venv/chhuti/bin/activate pip install --upgrade pip - Reinstall your project dependencies:
pip install django==1.11 celery redis
Second: Resolve the "Redis is not install" Error
Once pip is working again, let's fix the Redis-related issue—this error often refers to the system Redis service not being installed (not just the Python package):
Install Redis Server on your system:
- Debian/Ubuntu:
sudo apt-get install redis-server - CentOS/RHEL:
sudo yum install redis
- Debian/Ubuntu:
Start and enable the Redis service to ensure it runs on boot:
sudo systemctl start redis sudo systemctl enable redisVerify Redis is running properly:
redis-cli pingYou should see a response of
PONGif the service is working as expected.Ensure the Python Redis package is installed:
pip install redisDouble-check your Celery configuration in your Django
settings.py:CELERY_BROKER_URL = 'redis://localhost:6379/0' CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'Restart your Celery worker to apply all configuration changes:
celery -A your_project_name worker --loglevel=info
After completing these steps, try registering a new user again—both the pip and Redis issues should be resolved.
内容的提问来源于stack exchange,提问作者Amir Hossain

