introduction
As one of the most popular programming languages today, Python is widely used in data analysis, artificial intelligence, web development and other fields. However, many users often encounter various problems when installing, uninstalling Python or configuring the environment, such as:
-
python
orpip
The command cannot be recognized - Uninstalling Python failed (Error code
0x80070643
) - Virtual environment creation failed
- Relying on installation error
This article will provide complete solutions from Python installation, environment variable configuration, uninstallation and repair, virtual environment management, etc., and combine actual cases and code examples to help you completely solve these problems.
Part 1: Python installation and environment variable configuration
1.1 Correctly install Python
Step 1: Download Python
Go toPython official websiteDownload the latest stable version (such as Python 3.).
Step 2: Check the key options during installation
In the installation interface, be sure to check:
-
Add Python to PATH
(Automatically configure environment variables) -
Install pip
(Package management tool) -
py launcher
(Supports multi-version Python switching)
Step 3: Verify the installation
After the installation is complete, open CMD or PowerShell and run:
python --version # Should return Python 3.pip --version # should return pip
If an error is reported, it meansPATH
Not configured correctly, it needs to be added manually.
1.2 Manually configure environment variables
If it is not checked during installationAdd Python to PATH
, need to be added manually:
- Find the Python installation path (such as
C:\Python312\
andC:\Python312\Scripts\
)。 - Add to system
PATH
:- Win + R → Input
→ Advanced → Environment variables.
- In system variables
Path
Added in:
- Win + R → Input
C:\Python312\ C:\Python312\Scripts\
- Restart the terminal and verify again
python
andpip
。
Part 2: Solution to Python uninstall failure
2.1 I encountered an error 0x80070643 when uninstalling Python
Method 1: Use Microsoft Repair Tools
- Download Program Install and Uninstall Troubleshooter.
- Select Uninstall Python 3.11.9 to automatically fix the problem.
Method 2: Manually delete residual files
- Delete the Python installation directory (such as
C:\Python311\
)。 - Clean the user directory:
C:\Users\<username>\AppData\Local\Programs\Python\
C:\Users\<username>\AppData\Roaming\Python\
- (Precaution!) Clean the registry:
- delete
HKEY_CURRENT_USER\Software\Python
andHKEY_LOCAL_MACHINE\SOFTWARE\Python
。
- delete
Method 3: Uninstall after reinstall
- Rerun the Python 3.11.9 installation package and select Repair.
- After the repair is complete, try uninstalling again.
Part 3: Virtual Environment and Dependency Management
3.1 Creating a virtual environment
# Install virtualenvpip install virtualenv # Create a virtual environmentpython -m virtualenv myenv # Activate (Windows PowerShell).\myenv\Scripts\activate
After activation, the terminal will display(myenv)
, means that you have entered the virtual environment.
3.2 Installation project dependencies
pip install -r
If the download is slow, you can use the domestic mirror:
pip install -r -i /simple
Part 4: Troubleshooting of FAQs
4.1 python or pip is not available
- examine
PATH
:
echo $env:PATH # Check whether Python path is included
- Reinstall Python, make sure to check it
Add Python to PATH
。
4.2 Virtual environment activation failed
- Windows PowerShell requires:
.\env\Scripts\activate
- CMD uses:
env\Scripts\
4.3 Dependency installation conflict
- use
--force-reinstall
Forced reinstallation:
pip install --force-reinstall package_name
Conclusion
This article introduces Python installation, uninstallation, environment configuration and virtual environment management in detail, and provides solutions for common errors. If you still have problems, you can:
- Check Python version and
PATH
Configuration. - use
python -m pip
Instead of direct callpip
。 - Try running the terminal with administrator privileges.
The above is the detailed content of the full guide to Python installation, uninstallation and environment configuration (solving common problems and errors). For more information about Python installation, uninstallation and configuration, please follow my other related articles!