Setting Environment Variables When Pip Doesn't Work on Windows

힘센캥거루
2023년 11월 6일(수정됨)
6
python

After installing Python on Windows, if the environment variables are not set, pip won't work.

In this case, you need to set the environment variables.

Follow the procedure below to set the environment variables.

1. Re-download Python and set it up in Modify mode

First, download the same version of Python you installed from the Python website.

If you don't know the version, press Win key + R to open Run, and then type cmd.

Setting Environment Variables When Pip Doesn't Work on Windows-1

Then, type python --version to find out the Python version.

Setting Environment Variables When Pip Doesn't Work on Windows-2

Once you know the version, go to the Python website and download Python.

Setting Environment Variables When Pip Doesn't Work on Windows-3

Run the downloaded Python file.

Setting Environment Variables When Pip Doesn't Work on Windows-4

When the window appears, click on the topmost option.

Setting Environment Variables When Pip Doesn't Work on Windows-5

Click on all the check buttons on the next screen.

Setting Environment Variables When Pip Doesn't Work on Windows-6

And then relaunch VS Code and try pip in Python.

If the error is still not resolved, try setting the Python path by following the method below.

2. Setting Environment Variables

First, press Win key + R to open Run, type cmd, and confirm. 

Setting Environment Variables When Pip Doesn't Work on Windows-7

Then, if you type python, the input prompt changes to >>>. At this point, enter the following:

import sys
sys.executable
Setting Environment Variables When Pip Doesn't Work on Windows-8

The path that appears is the Python path. The usual paths for Python installation are one of the following:

# Python installation path 1
C:/Program Files/Python3x/python.exe

# Python installation path 2
C:/Users/Username/AppData/Local/Programs/Python/Pyhon3x/python.exe

Navigate to the respective path and check Python.

Then copy the path.

Setting Environment Variables When Pip Doesn't Work on Windows-9

Then, right-click on the Windows Start button.

Go to System >> Information >> Advanced system settings from the menu.

Setting Environment Variables When Pip Doesn't Work on Windows-10

Then, in System Properties >> Environment Variables >> Edit the system variables at the bottom, click New, and paste the copied path.

The two paths you need to paste are the Python path and the path of Scripts inside the Python folder.

Setting Environment Variables When Pip Doesn't Work on Windows-11

Then, relaunch VS Code and execute pip in the terminal.

If it still doesn't work, you need to change the default terminal.

3. Change Default Terminal

If pip still doesn't execute, try changing the default terminal.

In VS Code, press the F1 key, search for Terminal:Select Default Profile, and click it.

Setting Environment Variables When Pip Doesn't Work on Windows-12

Change the default terminal from powershell.exe to cmd.exe.

Setting Environment Variables When Pip Doesn't Work on Windows-13

Then try installing with pip again.

4. Summary - When pip does not execute

  1. Rerun the Python installer >> Modify >> Check all checkboxes >> Reboot or relaunch VS Code

  2. Windows System Settings >> Environment Variables >> Add Python, scripts path

  3. Change VS Code default terminal

If there are any other methods besides the three mentioned above, I plan to add them later.

댓글을 불러오는 중...