SoFunction
Updated on 2025-05-07

Python installation, uninstallation and environment configuration guide (solve common problems and errors)

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:

  • pythonorpipThe command cannot be recognized
  • Uninstalling Python failed (Error code0x80070643
  • 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 meansPATHNot 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:

  1. Find the Python installation path (such asC:\Python312\andC:\Python312\Scripts\)。
  2. Add to systemPATH
    • Win + R → Input→ Advanced → Environment variables.
    • In system variablesPathAdded in:
C:\Python312\
C:\Python312\Scripts\
  • Restart the terminal and verify againpythonandpip

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

  1. Delete the Python installation directory (such asC:\Python311\)。
  2. Clean the user directory:
    • C:\Users\<username>\AppData\Local\Programs\Python\
    • C:\Users\<username>\AppData\Roaming\Python\
  3. (Precaution!) Clean the registry:
    • deleteHKEY_CURRENT_USER\Software\PythonandHKEY_LOCAL_MACHINE\SOFTWARE\Python

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

  • examinePATH
echo $env:PATH  # Check whether Python path is included
  • Reinstall Python, make sure to check itAdd 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-reinstallForced 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:

  1. Check Python version andPATHConfiguration.
  2. usepython -m pipInstead of direct callpip
  3. 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!