使用Pipenv安装Django遇异常:日志显示成功仍报错
Hey there, let's unpack this tricky issue you're facing—even though the install log says everything worked, something's clearly off with your Django setup. Let's walk through practical fixes step by step:
First, let's rule out the most common oversight:
- Confirm you're working inside the Pipenv virtual environment
It's easy to forget to activate the shell and end up checking your global Python instead. Try either:
Or skip the shell and run directly through Pipenv:# Activate the shell first pipenv shell django-admin --version
If this returns a Django version (like 2.0.3), the install actually succeeded—you just weren't checking the right environment!pipenv run django-admin --version
Next, verify Pipenv's configuration files:
- Check your Pipfile and Pipfile.lock
Open your project'sPipfileand look under the[packages]section. You should see entries like:
If these lines are missing, the install didn't properly register with Pipenv. Do the same check fordjango = "==2.0.3" pytz = "==2018.3"Pipfile.lock—search for "django" to confirm it's listed with the correct version.
If those check out, try these targeted fixes:
Clear Pipenv's cache and do a fresh install
Corrupted cached packages can cause false "success" messages. Wipe the cache and reinstall with:pipenv install django --clearEnsure Pipenv uses your intended Python version
Even if you switched system Python versions, Pipenv might still be tied to an old virtual environment. Check which Python your environment uses:pipenv --pyIf it's not 3.5 or 3.6.4, create a new environment with the specific version:
pipenv --python 3.6.4 pipenv install djangoGet verbose install logs
The default log might hide subtle errors. Run the install with verbose output to see the full process:pipenv install django --verboseLook for any warnings, skipped steps, or error messages that didn't show up in the default log.
Test Django import directly
Activate the shell and run this command to test if Django is actually installed in the environment:pipenv shell python -c "import django; print(django.__version__)"If this throws an
ImportError, the error message here will point you to the root cause—like missing dependencies or a version mismatch.
Let me know which step helps you track down the issue!
内容的提问来源于stack exchange,提问作者Cameron Chin

