• Business
    • Agriculture & Farming
    • Cryptocurrency
    • Economics
    • Transport
  • Celebrity
  • Education
    • Education & Training
  • Humanities
    • Global Warming
    • Human Rights
    • Jobs
    • Shopping & Retail
  • Medical
  • Politics
    • Crime and Justice
    • Immigration
    • Military
    • Religion
  • Sport
    • American Football
    • Golf
    • Motor racing
    • Soccer
    • Tennis
  • Tech
    • Cybersecurity
    • Space
  • |
  • About
  • Contact
  • Editorial
Wednesday, September 20, 2023
  • Login
  • Register
THX News | Global News, Travel & Education.
American National Standards Institute Inc.
ADVERTISEMENT
  • USA
  • Canada
  • Central America
  • South America
  • Europe
  • Middle East
  • Africa
  • Asia
  • Oceania
No Result
View All Result
THX News | Global News, Travel & Education.
  • USA
  • Canada
  • Central America
  • South America
  • Europe
  • Middle East
  • Africa
  • Asia
  • Oceania
Contact Us
THX News | Global News, Travel & Education.
No Result
View All Result
Home Education Technology

Supercharge Your Python Development with Virtual Environments

Effortlessly manage dependencies, boost productivity, and maintain project consistency.

Neil Brand by Neil Brand
2 months ago
in Technology
Reading Time: 9 mins read
0 0
A A
5 steps to setup Python env on windows.

5 steps to setup Python env on windows. Artwork by Neil Brand.

0
VIEWS
Share on FacebookShare on TwitterShare on Pinterest

Table of Contents

  • Introduction:
  • Step 1: Creating the Directories
  • Step 2: Downloading the Python Version
  • Step 3: Installing the Python Version
  • Step 4: Creating a Virtual Environment
  • Step 5: Activating the Virtual Environment
  • Bonus: Setting Up VSCode and Pylance to Use the Virtual Environment (for VSCode Users)

 

Introduction:

Are you ready to take your Python development skills to the next level? If you’re passionate about writing Python code and building powerful applications, then it’s crucial to embrace the practice of using virtual environments. Trust me, it will revolutionize the way you develop and manage your Python projects!

In the world of Python development, virtual environments play a vital role in keeping your project dependencies isolated, maintaining consistency across different projects, and ensuring smooth collaboration with other developers.

Whether you’re a seasoned Pythonista or just getting started, virtual environments are an essential tool in your developer’s arsenal.

In this step-by-step guide, I’ll walk you through the process of setting up and using virtual environments on Windows machines using the venv module.

I’ll cover everything from installation to activation and demonstrate how virtual environments can help you avoid version conflicts, manage project dependencies effortlessly, and create a clean and organized development environment.

So, if you’re ready to supercharge your Python development workflow, let’s dive into the eleven easy steps to harnessing the power of virtual environments on Windows machines. Don’t worry if you’re new to this – I’ll explain each step in detail and provide helpful tips along the way.

Let’s get started!

 

Step 1: Creating the Directories

Before we dive into setting up virtual environments using venv, let’s start by creating the necessary directories. While this step is a matter of personal preference, especially if you already have a specific directory structure in place, I’ll guide you through creating two directories: “virtual_envs” and “pyvers.”.

My actual structure looks like this: <development folder>/<python_projects>/<virtual_envs>/<a bunch of virtual envs in their own folders>. Also inside the <python_projects> folder, I have the <pyvers>/<pyXXX> folders.

Your mileage will vary but if you’re fresh to Python or programming in general, it’s a good idea to have a development directory that you can keep all of your code inside.

Creating these directories will help you organize your virtual environments and Python versions in a neat and structured manner. Here’s how you can create them:

  1. Open File Explorer on your Windows machine.
  2. Navigate to the location where you want to create the directories. This could be your user directory or any other location of your choice.
  3. Right-click in the desired location and select “New” from the context menu.
  4. Choose “Folder” from the submenu.
  5. Name the first folder “virtual_envs” (without quotes). This folder will serve as the parent directory for your virtual environments.
  6. Repeat steps 3 to 5 to create the second folder and name it “pyvers” (without quotes). This folder will house different Python versions.

 

Once you’ve completed these steps, you’re ready to move on to the next step in setting up your virtual environment using venv.

 

Step 2: Downloading the Python Version

Before we can create a virtual environment, we need to have the desired Python version installed on our Windows machine. If you already have the Python version you want to use, you can skip this step. Otherwise, let’s download and install the Python version of your choice by following these steps:

  1. Open a web browser and visit the official Python website at python.org.
  2. On the Python website, click on the “Downloads” tab located in the top navigation menu.
  3. You’ll be presented with different Python versions to choose from. Select the version that suits your project requirements. It’s generally recommended to choose the latest stable version unless you have specific reasons for using an older version.
  4. Once you’ve selected the version, scroll down the page to the downloads section. You’ll find different installers for various operating systems. Look for the Windows installer appropriate for your system (32-bit or 64-bit) and click on it to start the download.

 

Step 3: Installing the Python Version

  1. Locate the downloaded file (e.g., python<ver number>.exe) and run it by double-clicking on it. This will launch the Python installer.
  2. IMPORTANT: Make sure to UNCHECK the “Add Python to PATH” option during the installation process. This is an important step as we will handle the environment configuration manually.
  3. Click on the “Customize Installation” button as we will be making additional customizations.
  4. In the customization window, click “Next” to proceed, unless you have specific options you want to modify. Feel free to uncheck the “Documentation” option if you don’t need it, as it will reduce the installation size.
  5. Next, you will be prompted to choose the installation directory. Click on the “Browse” button and navigate to the “pyvers” directory you created earlier. Note that Python automatically suggests a directory name in the format “Python<version number>” for the version being installed. To maintain consistency, consider changing this directory name to “py<version number>”. For example, you can set the installation directory to “…pyvers\py311” for Python version 3.11. If you plan to install different minor versions, you can add the specific minor version at the end of the directory name for clarity.
  6. Once you’ve selected the desired installation directory, click “Next” to proceed.
  7. The installer will now install Python in the chosen directory. After the installation is complete, a confirmation screen will be displayed.

 

Congratulations! You’ve successfully downloaded and installed the Python version of your choice, customized the installation directory, and ensured that Python is not added to the PATH automatically. With the Python version installed in the “pyvers” directory, we’re now ready to move on to the next step, where we’ll create our first virtual environment using venv on Windows.

 

Step 4: Creating a Virtual Environment

Now that we have the desired Python version installed and our directories set up, it’s time to create our first virtual environment using the venv module. Follow these steps to create a virtual environment for your project:

  1. Open the Command Prompt on your Windows machine. You can do this by pressing the Win + R keys to open the Run dialog, typing “cmd” (without quotes), and pressing Enter.
  2. In the Command Prompt Type: <path to pyver>\<py ver>\python -m venv <path to virtual_envs>\<name of project>
    Replace <path to pyvers> with the actual path to your “pyvers” directory and <py ver> with the specific Python version you installed.
    Also, make sure to replace <path to virtual_envs> with the actual path to your “virtual_envs” directory, and <name of project> with the desired name for your project.For example, if you’re creating a project called “my_awesome_project,” the command would look like this: <path to pyver>\<py ver>\python -m venv <path to virtual_envs>\my_awesome_projectThis command will create a virtual environment named “my_awesome_project” within the “virtual_envs” directory.
  3. Press Enter to execute the command. The virtual environment will be created, and you’ll see a new folder named “my_awesome_project” (or the name you chose) within the “virtual_envs” directory.

 

Great! You’ve successfully created a virtual environment for your project. This virtual environment will provide an isolated Python environment with its own installed packages and dependencies.

In the next step, we’ll activate the virtual environment and start utilizing it for our Python development.

 

Step 5: Activating the Virtual Environment

Now that we have our virtual environment created, we can activate it and start using it for our Python development. Follow these steps to activate your virtual environment:

  1. Open the Command Prompt on your Windows machine. You can do this by pressing the Win + R keys to open the Run dialog, typing “cmd” (without quotes), and pressing Enter.
  2. In the Command Prompt, run the following command to activate your virtual environment:
    <path to your new venv>\Scripts\activate
    Replace <path to venv> with the actual path to your virtual environment. For example, if your virtual environment is named “my_awesome_project” and located in the “virtual_envs” directory, the command would look like this: <path to virtual_envs>\my_awesome_project\Scripts\activate

 

Running this command will activate the virtual environment, and you’ll notice that the Command Prompt changes to reflect the activated environment.

Once the virtual environment is activated, you can start using Python and installing packages specific to this environment. Any Python packages you install or scripts you run will be isolated within this virtual environment, keeping your project dependencies organized and separate from the global Python installation.

Well done, you’ve successfully activated your virtual environment! Remember, whenever you’re working on your project and want to access the virtual environment, you’ll need to activate it using the activate command we just discussed.

You can also use deactivate if you want to switch venvs, just used the same command with deactivate in place of activate.

 

Bonus: Setting Up VSCode and Pylance to Use the Virtual Environment (for VSCode Users)

If you’re using Visual Studio Code (VSCode) as your preferred code editor (and found Pylance causing issues with “module not found” when it’s clearly installed…), we’ve got you covered!

Here’s a bonus section on how to configure VSCode and Pylance to use the virtual environment we just created. Let’s get started:

  1. In Visual Studio Code, Press Shift + Ctrl + P simultaneously to open the command palette. This can also be accessed by clicking on “View” in the top menu and selecting “Command Palette.”
  2. In the command palette, type “python” and choose “Python: Select Interpreter” from the list of options that appears. Press Enter to select it.
  3. In the next box that appears, you’ll see a list of available Python interpreters. Look for the option “+ Enter interpreter path…” and select it. This option allows us to specify the path to our virtual environment’s Python interpreter.
  4. A textbox will appear, prompting you to enter the interpreter path. Enter the path to the Python interpreter within your virtual environment. The path should be in the following format: <path to virtual_envs>\<your_new_env>\Scripts\Python.exe
  5. After entering the interpreter path, press Enter to confirm your selection.

That’s all there is to it! You’ve successfully configured VSCode and Pylance to use the virtual environment’s Python interpreter. Now, when you work on your project within VSCode, it will automatically use the Python interpreter from the virtual environment.

This setup ensures that any Python packages you install or dependencies you manage within the virtual environment will be utilized by VSCode, providing seamless integration between your code editor and the virtual environment.

Hopefully, this helps you to manage your Python projects in a cleaner and more manageable way!

Thank you for reading!

 

Sources: THX News & Neil Brand.

Tags: Activating virtual environmentsIsolated Python environmentsManaging Python dependenciesPython development workflowPython project organizationPython version installationPython virtual environmentsSetting up virtual environmentsVirtual environments for PythonWindows machine virtual environments
Paul Smith USA - Summer Sale Paul Smith USA - Summer Sale Paul Smith USA - Summer Sale
ADVERTISEMENT
Neil Brand

Neil Brand

Hey there! I'm Neil, a web developer with over 23 years of experience under my belt and I absolutely love what I do. Programming, web development, and technology? They're my true passions. The digital world is my playground, and I thrive on the constant evolution and exciting challenges it brings. It's like a never-ending adventure, always pushing me to explore new possibilities and innovate.

Related Posts

Oracle Database@Azure. Microsoft and Oracle Expand Partnership. Artwork by Oracle.
Technology

Oracle Database@Azure: A Cloud Revolution

September 14, 2023
Artificial Intelligence Benefits. Photo by Geralt. Pixabay.
Technology

Artificial Intelligence Benefits: Keeping Up with New Technologies 

July 28, 2023
what your website is header. Artwork by Neil Brand.
Technology

What Your Website Is and Isn’t

July 23, 2023
Supply Chain. Photo by EpicTop10. Flickr.
Technology

Unlocking the Potential of Blockchain Technology in Supply Chain Management

June 24, 2023
App augmented reality game gps. Photo by Pixabay.
Technology

Beyond Virtual Reality: Delving into the World of Augmented Reality Gaming

June 23, 2023
WIRED Editorial Superposition on D-Wave and The Age of Quantum Computing. Photo by Steve Jurvetson. Flickr.
Technology

Exploring The Future of Quantum Computing in Real-World Applications

July 9, 2023

Asian Travel

DPC Dash Franchisee Shines: Domino’s Pizza China Excellence

by Ivan Golden
August 21, 2023
0
Domino's in Shanghai, China. Domino's Pizza China franchisee expands. Photo by Mr Thinktank. Flickr.

  A Notable Achievement for DPC Dash Ltd DPC Dash Ltd, the exclusive master franchisee for Domino's Pizza in Mainland...

Read more

Secretary Blinken Holds Constructive Talks with Chinese Foreign Minister in Beijing

by Ivan Golden
June 18, 2023
0
U.S. Secretary of State Anthony J. Blinken. Photo by USEmbassySA. Flickr.

BEIJING — In a significant diplomatic engagement, Secretary of State Antony J. Blinken engaged in candid and substantive discussions with...

Read more

Business Receipts Surge in Hong Kong’s Service Industries, Driven by Tourism and Domestic Demand

by Ivan Golden
June 9, 2023
0
Hong Kong Waterfront. Photo by Martin Pilkington. Flickr.

  Growth in Major Service Industries Business receipts in value terms of several major service industries in Hong Kong witnessed...

Read more
Panasonic MultiShape Evergreen Banners - Next Level Grooming. Home Page.
ADVERTISEMENT

Asian Travel

Philippine Economy: ADB’s 5.7% Estimated Growth in 2023

by Ivan Golden
September 20, 2023
0
Philippine economic growth. Asian development bank in Manila. Photo by Wasiul Bahar. Wikimedia.

  Economic Outlook for 2023 In a surprising move on Wednesday, the Manila-based Asian Development Bank (ADB) revised its economic...

Read more

Senator Villar Fights Scams with New Law

by Ivan Golden
September 18, 2023
0
Senator Mark Villar. Photo by the PNA.

  Alarming Increase in Scam Cases Senator Mark Villar emphasized the urgent need to craft robust legislation to combat scammers...

Read more

Cebu City’s Battle Against Flooding Obstacles

by Ivan Golden
September 18, 2023
0
Mayor Michael Rama on Monday said Cimatu is coming to Cebu City. Photo by Cebu City PIO. PNA.

  A Call to Action After Severe Flooding In the wake of severe flooding in the Banilad area of Cebu...

Read more
Careerist
ADVERTISEMENT

Middle East News

Iraq-KRG Dialogue: Safeguarding Democracy and Stability

by Ivan Golden
September 18, 2023
0
Iraq-KRG dialogue. Kurdistan Regional Government. Photo by Foreign, Commonwealth and Development Office. Flickr.

  A Constructive Dialogue In a significant diplomatic development, National Security Advisor Jake Sullivan has welcomed the recent constructive dialogue...

Read more

Quad Nations Condemn Iran’s IAEA Inspector Withdrawal

by Ivan Golden
September 18, 2023
0
Graffiti in Jerusalem. Photo by Copper Kettle. Flickr.

The text of the following statement was released by the permanent representatives to the IAEA of France, Germany, the United...

Read more

Iran Spotlight: UK Sanctions Spark Change

by Ivan Golden
September 15, 2023
0
Foreign & Commonwealth Office. Photo by FCDO. UK.GOV.

  UK Stands Firm in Support of Iranian People In a powerful show of solidarity, the UK Foreign Secretary, James...

Read more
Careerist
ADVERTISEMENT
THX News | Free News, Travel & Education

Stay informed, inspired, and connected with THX News—your gateway to a world of knowledge.

Unleash your curiosity, and explore the latest news, captivating travel blogs, and insightful educational articles.

We bring the world to your fingertips, empowering you to shape your own narrative.

Article Search

No Result
View All Result

Categories

Archives

Craftsmen working hard to make traditional Indonesian handicrafts. Photo by Shankar S. Flickr.

Unlocking Workplace Happiness: HP Work Relationship

September 20, 2023
African climate change workshop group. Photo by Discott. Wikimedia.

Africa’s Climate Change Views: Afrobarometer Insights

September 20, 2023
Philippine economic growth. Asian development bank in Manila. Photo by Wasiul Bahar. Wikimedia.

Philippine Economy: ADB’s 5.7% Estimated Growth in 2023

September 20, 2023
  • Terms of Use
  • Privacy Policy
  • RSS

THX News™ 2023

No Result
View All Result
  • News
    • Business
    • Celebrity
    • Economics
    • Global Warming
    • Human Rights
    • Medical
    • Military
    • Politics
    • Space & Exploration
    • Technology
    • Africa
    • Asia
    • Canada
    • Central America
    • Europe
    • Middle East
    • Oceania
    • South America
    • USA
  • Travel
    • Africa
    • Asia
    • Canada
    • Central America
    • Europe
    • Middle East
    • Oceania
    • South America
    • USA
  • Education
    • Books & Authors
    • History
      • Wild West Celebrities
      • Company Histories
    • Parenting
    • Science
    • Technology
    • US Universities
    • More
  • About Us
  • Help
  • Contact
  • Login
  • Sign Up

THX News™ 2023

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms below to register

*By registering into our website, you agree to the Terms & Conditions and Privacy Policy.
All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.