Installing Python on Windows + Setting the PATH — When 'python' Is Not Recognized

After working only on Java Spring Boot projects, I had to develop in Python. This post sets up Python-related environment variables on Windows, installs the needed libraries/packages, and looks at Python's package structure. (Linux will come in a separate post.)

Installing Python

Download the installer from the official site, python.org.

Version selection screen on the Python official site Figure 1. Choosing a Python version (as of 2024-10-13)

I picked 3.11, the latest security release at the time, and installed it on the Windows D drive.

Python installer executable (exe) Figure 2. The Python installer (exe)

During installation, I chose Customize Installation and set the install path to D:\Python. (Set the path wherever you like.)

Directory structure of the Python install path (D:\Python) Figure 3. Directory layout after installing Python

Setting the PATH environment variable

1. What is an environment variable?

Setting environment variables provides the OS with program paths, global settings, and system configuration so that applications and commands can reference them.

The reason languages like Java and Python use environment variables is to run a compiler or interpreter executable by name rather than by absolute path. For example, to run python.exe you'd otherwise have to type the absolute path D:\Python\python.exe in cmd. Since that's inconvenient every time, we tell the OS the path so typing just python works. (This concept applies to Linux as well, not only Windows.)

Typing python without a PATH set opens the Microsoft Store Figure 4. Running the python command without a PATH set

Figure 4 shows that, without the PATH set, typing python isn't recognized and the Microsoft Store opens. (Normally you'd get a "path not found" message, but depending on your PC it may be wired like this.)

Python runs when the absolute path D:\Python\python.exe is entered Figure 5. Entering the absolute path

As in Figure 5, entering the absolute path D:\Python\python.exe runs Python. Now we'll tell the OS this path so that just python runs it.

2. Setting the PATH (Windows)

Searching for "Edit the system environment variables" Figure 6. Edit the system environment variables

  1. As in Figure 6, search for "Edit the system environment variables," or
  2. Control Panel → System and Security → System → Advanced system settings

The Environment Variables button in System Properties Figure 7. The system environment variables window

Following the above brings up the window in Figure 7; click Environment Variables (N).

Environment Variables window split into User variables and System variables Figure 8. The Environment Variables window

As in Figure 8, the window is split into User variables (U) and System variables (S). The difference is scope.

  • User variables — apply only to the current user. Each user has their own and they don't affect other users.
  • System variables — apply to all users, available system-wide.

Here we set it under System variables so it applies to all users.

Selecting and editing Path under System variables Figure 9. Setting Path in System variables

Under System variables (S), double-click Path, or select it and click Edit (I).

Adding a new path in the Path edit window Figure 10. Adding the Python path

Click New (N) in Figure 10 to enter a path. For Python's PATH, you add two paths.

The two Python paths to add Figure 11. The two paths to add

  1. D:\Python — where the python.exe executable is installed
  2. D:\Python\Scripts — where package managers like pip.exe / pip3.exe are installed

(The exact paths depend on your install location, but the structure — python.exe under the install path and pip inside Scripts — is the same.)

💡 pip — Python's official package manager. It installs libraries like numpy, scipy, pandas, and tensorflow via pip install. It plays a role similar to JavaScript's npm and the dependency management of Java's Maven/Gradle.

3. Verifying the PATH

Adding and applying the two paths completes the Python environment variable setup.

python and pip commands working in cmd Figure 12. PATH setup result

As in Figure 12, it's working if python launches Python and pip prints the package manager help in cmd.

4. Directory structure of pip-installed libraries

Let's install libraries like numpy and pandas with pip3 install.

Installing pandas with pip Figure 13. Installing pandas via pip

Libraries installed this way are stored by default in D:\Python\Lib\site-packages. As seen in Figure 3, there is a Lib directory under the Python install path, and a site-packages folder inside it.

numpy and pandas installed under site-packages Figure 14. Where pip-installed libraries are stored

In Figure 14 you can see numpy, pandas, and others installed by pip inside site-packages.

Managing the libraries and versions installed with pip this way helps prevent conflicts and keeps things organized.


With your environment variables set, it's time to install FastAPI and run your first server.

Getting Started with Python FastAPI — Concepts, Install & Running on PyCharm (feat. uvicorn)
Why FastAPI (async / I/O-bound) and how it relates to Python's GIL, installing FastAPI and uvicorn with pip, the relationship between a web framework and a web application (ASGI/WSGI), and two ways to run the server with uvicorn in PyCharm plus the built-in Swagger UI.
taystudios.com/blog

📦 Migrated from my own Korean blog (my own writing). Original: taehyuklee.tistory.com/20

Share𝕏f

Comments