Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Setting up a Python Development Environment on Windows 10

Tech May 9 4

Installing Python

To establish a Python development environment on Windows 10, the initial step involves installing Python itself. This process resembles installing any standard software application: downloading the installer from the official Python website and executing it.

Visit https://www.python.org and navigate to the "Downloads" section for Windows. Here, you'll find multiple versions available for download. It's crucial to select an apropriate version:

Python 2 has reached end-of-life and is no longer maintained, with its last release being Python 2.7.18. In contrast, Python 3 represents a significant evolution with non-backward-compatible changes and continues to receive updates, with the latest stable version at the time of writing being 3.9.6.

Given that Python 2 is deprecated, it's advisable to install Python 3 unless there's a specific requirement to use Python 2 (such as compatibility with certain packages). For stability, opt for a well-tested version rather than the absolute latest, as newer releases might not yet be fully supported by all libraries.

After selecting the desired version, download either the Windows installer (.exe) or the executable installer depending on whether your system is 32-bit or 64-bit. Once downloaded, run the .exe file and choose between default installation or custom configuration. Ensure the option "Add Python to PATH" is enabled during setup.

Upon successful installation, you can execute Python scripts through the command line. Open Command Prompt and type python, followed by pressing Enter to verify the installed version. Alternatively, you can run a script directly using python path\to\script.py.

The PATH environment variable allows the system to locate Python executables without specifying full paths. This is essential for running Python commands from any directory and for package management tools like pip to function correctly.

Configuring VS Code for Python

Visual Studio Code (VS Code) serves as a powerful integrated development environment for Python. Download and install VS Code from https://code.visualstudio.com/. After installation, switch to the Chinese language pack via the Extensions panel by searching for "Chinese".

Next, install the official Python extension from Microsoft to enable Python-specific features such as syntax highlighting, code completion, and debugging capabilities.

Once installed, create a new Python file in VS Code. Choose Python as the language mode, which will activate the Python extension. You should see the selected Python interpreter displayed in the lower-left corner of the status bar.

Managing Virtual Environments

Virtual environments isolate dependencies for different projects. Using the built-in venv module, create isolated environments for each project:

python -m venv D:\myProject\venv

Navigate to the virtual environment's activation script based on your shell:

For Command Prompt:

D:\myProject\venv\Scripts\activate.bat

For PowerShell:

D:\myProject\venv\Scripts\Activate.ps1

Note: PowerShell may require setting execution policy if encountering permission errors:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Once activated, your terminal prompt will show the environment name. To exit the virtual environment, simply run deactivate.

In VS Code, ensure the correct interpreter is selected by clicking the Python version indicator in the status bar and choosing the virtual environment's Python executable located within the venv\Scripts directory.

Version Control with Git

Git facilitates tracking and managing changes in your Python projects. Install Git from https://git-scm.com/downloads and configure your identity:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Initialize a repository in your project folder:

mkdir myProject
 cd myProject
git init

Track files using git add and commit changes with git commit:

git add myCode1.py
 git commit -m "Initial commit"

Monitor changes with git status and review differences with git diff. Use git log to view history and git reset --hard HEAD^ to revert to previous states.

VS Code provides a graphical interface for Git operations under the Source Control tab, simplifying workflow management.

With these components in place, your Python development setup includes a reliable interpreter, isolated environments, and version control.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.