Python新手求助:VS Code执行pipenv install --python3.9报错
pipenv install --python3.9 Hey there, let's sort out this pipenv mess you're dealing with!
First off, I spot a critical syntax issue in your command: you’re using --python3.9 instead of the correct --python 3.9 (note the space between --python and the version number). When you skip that space, pipenv mistakenly treats --python3.9 as a package name to install—which is why it’s throwing that parsing error, since that’s not a valid package identifier format.
On top of that, all those random install operations from different tutorials probably corrupted your pipenv environment or some core dependency packages. Here’s a step-by-step fix to get things back on track:
Clean up the broken environment
- If there’s a
PipfileorPipfile.lockin your project folder, delete them first to start fresh. - Run
pipenv --rmto remove the messed-up virtual environment linked to your project. - Clear pipenv’s cache to eliminate any corrupted package files:
pipenv cache clear
- If there’s a
Fix core Python dependencies
- Upgrade your pip to ensure it’s functioning correctly:
python3.9 -m pip install --upgrade pip - Uninstall and reinstall pipenv to refresh it completely:
pip uninstall -y pipenv python3.9 -m pip install pipenv - Upgrade
setuptoolsandpyparsing—these are core tools that handle dependency parsing, and they’re likely acting up:python3.9 -m pip install --upgrade setuptools pyparsing
- Upgrade your pip to ensure it’s functioning correctly:
Create a fresh working environment
Navigate back to your project directory, then run the properly formatted command:pipenv install --python 3.9
This should resolve the parsing error and get your pipenv environment working again. The combination of the incorrect command syntax and corrupted dependencies from all those tutorial installs was the root cause here.
内容的提问来源于stack exchange,提问作者yuyu

