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.
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.
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.)
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.)
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.)
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)
Figure 6. Edit the system environment variables
- As in Figure 6, search for "Edit the system environment variables," or
- Control Panel → System and Security → System → Advanced system settings
Figure 7. The system environment variables window
Following the above brings up the window in Figure 7; click Environment Variables (N).
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.
Figure 9. Setting Path in System variables
Under System variables (S), double-click Path, or select it and click Edit (I).
Figure 10. Adding the Python path
Click New (N) in Figure 10 to enter a path. For Python's PATH, you add two paths.
Figure 11. The two paths to add
D:\Python— where thepython.exeexecutable is installedD:\Python\Scripts— where package managers likepip.exe/pip3.exeare 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.
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.
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.
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.
📦 Migrated from my own Korean blog (my own writing). Original: taehyuklee.tistory.com/20

Comments