Complete Guide: Setting Up Python and Poetry Development Environment on Windows 11/10

Akshay KambleAkshay Kamble
6 min read

Setting up a robust Python development environment on Windows can be complex, especially when configuring modern dependency management tools like Poetry. This comprehensive guide walks you through the entire process, from Python installation to Poetry configuration, with solutions for common issues, ensuring you have a smooth setup.


Prerequisites

Before we dive in, make sure you have the following:

  • Windows 10 or 11: These steps are applicable to both operating systems.

  • Administrator Privileges: You might need administrator rights to install software and modify system environment variables.

  • PowerShell: We'll be using PowerShell for some commands. Ensure your PowerShell execution policy allows local scripts to run. If not, open PowerShell as an administrator and run: PowerShell You might be prompted to confirm; type Y and press Enter.

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser


Python Installation

There are two primary ways to install Python on Windows. I personally recommend the installer from the official site for better control and the latest stable versions.

Method 1: Python Installation via Microsoft Store

You can install Python directly from the Microsoft Store. This method is convenient as it handles updates automatically. However, there might be a slight delay in new Python versions becoming available on the store.

  1. Open the Microsoft Store app.

  2. Search for "Python" and select the version you wish to install (e.g., "Python 3.10").

  3. Click "Get" or "Install" and follow the on-screen prompts.

This is my preferred method as it ensures you get the stable and reliable build directly from the official source.

  1. Open your web browser and go to the official Python website.

  2. Download the latest stable Windows installer (e.g., "Windows installer (64-bit)").

  3. Once the download is complete, run the installer.

  4. Crucially, on the first installation screen, make sure to check the box that says "Add Python to PATH" (or "Add Python X.Y to PATH"). This step is vital as it tells your system where to find the Python executable.

  5. Click "Install Now" and follow the remaining prompts.


Verifying Python Installation

After installation, it's essential to verify that Python has been added to your system's PATH correctly.

  1. Open PowerShell (you can search for it in the Start menu).

  2. Type the following command and press Enter: PowerShell

python --version
  1. Expected Output: You should see the installed Python version, for example:
Python 3.10.x

Alternatively, you can use:


python -V

If you receive a "command not found" error, ensure you checked the "Add Python to PATH" option during installation. If not, you might need to reinstall Python or manually add it to your environment variables (refer to the "Configuring Poetry Environment Variables" section for guidance on adding paths).


Installing Poetry

In Python development, managing dependencies and creating isolated environments is crucial. While requirements.txt is common, it often lacks precision and requires manual maintenance. Poetry automates much of this, providing a robust and reproducible dependency management system.

Poetry generates a poetry.lock file that records the exact versions of all dependencies, including transitive (indirect) ones. This ensures that every environment—across developers, CI/CD pipelines, or production—installs the exact same package versions, eliminating "works on my machine" issues. It also automatically creates and manages a dedicated virtual environment for each project, significantly reducing setup time and avoiding global package pollution.

To install Poetry, we'll use the official recommended PowerShell command:

  1. Open PowerShell.

  2. Run the following command: PowerShell This command downloads and automatically installs Poetry on your system.

    (Invoke-WebRequest -Uri <https://install.python-poetry.org> -UseBasicParsing).Content | py -

  3. Once the installation is complete, you should see a success message indicating where Poetry has been installed. Take note of this path, as it might be needed for troubleshooting. A typical path is C:\\Users\\<YOUR_USERNAME>\\AppData\\Roaming\\pypoetry.


Verifying Poetry Installation

To confirm Poetry is installed and accessible:

  1. Close and reopen PowerShell. This refreshes the environment variables, allowing the system to recognize the new Poetry command.

  2. In the new PowerShell window, type: PowerShell

poetry --version

Expected Output: You should see the installed Poetry version, for example:

Poetry (version 1.8.x)

If you get a "command not found" error, proceed to the next section.


Configuring Poetry Environment Variables (For "Command Not Found" Errors)

If you're still encountering a "command not found" error after installing Poetry and restarting PowerShell, it means your system doesn't know where to find the Poetry executable. We need to add its installation path to your system's PATH environment variable.

  1. Locate the Poetry Executable Path:

    • Open File Explorer.

    • Navigate to C:\\Users\\<YOUR_USERNAME>\\AppData\\Roaming\\pypoetry.

      • Note: The AppData folder is usually hidden. To see it, go to the "View" tab in File Explorer, click "Show/hide," and check "Hidden items."
    • Inside the pypoetry folder, navigate into venv\\Scripts.

    • The full path will look something like: C:\\Users\\<YOUR_USERNAME>\\AppData\\Roaming\\pypoetry\\venv\\Scripts.

    • Copy this entire path.

  1. Edit System Environment Variables:

    • Click on the Windows Start button.

    • Type "Environment variables" and select "Edit the system environment variables."

    • In the "System Properties" window, click the "Environment Variables..." button.

  1. Add to User Variables (PATH):

    • Under "User variables for <YOUR_USERNAME>", find and select the variable named Path (or PATH).

    • Click "Edit...".

    • In the "Edit environment variable" window, click "New".

    • Paste the Poetry executable path you copied earlier.

    • Click "OK" on all open windows to save the changes.

  2. Add to System Variables (PATH) - Optional but Recommended:

    • Repeat the previous step for the Path variable under "System variables." This ensures Poetry is accessible for all users on the system.
  3. Restart PowerShell:

    • Close all open PowerShell windows and then reopen a new one. This is crucial for the changes to take effect.

    • Now, try poetry --version again. It should work!


Common Issues and Solutions

  • "Command not found" for python:

    • Ensure "Add Python to PATH" was checked during installation.

    • Manually add Python's installation directory (e.g., C:\\Users\\<YOUR_USERNAME>\\AppData\\Local\\Programs\\Python\\Python3X) and its Scripts subdirectory (e.g., C:\\Users\\<YOUR_USERNAME>\\AppData\\Local\\Programs\\Python\\Python3X\\Scripts) to your PATH environment variable.

  • PowerShell Execution Policy: If you get an error when running the Invoke-WebRequest command for Poetry, ensure your PowerShell execution policy is set to RemoteSigned for the current user (as mentioned in the Prerequisites).

  • Antivirus/Firewall Interference: Sometimes, antivirus software or firewalls can block downloads or installations. Temporarily disable them if you suspect this is the case, but remember to re-enable them afterward.

  • Corporate Network/Proxy: If you're on a corporate network, proxy settings might interfere with downloads. Consult your IT department or try setting proxy environment variables if you know them.

  • Permissions Issues: Ensure you have sufficient permissions to install software and modify environment variables. Run PowerShell or the installer as an administrator if needed.


Next Steps and Best Practices

  • Explore Poetry Commands: Dive deeper into Poetry's capabilities by exploring its commands like poetry install, poetry update, poetry export, etc. Refer to the official Poetry documentation for more details.

Additional Resources


I hope this comprehensive guide helps you set up your Python and Poetry development environment on Windows with ease! If you found this helpful, please like and share it with others who might benefit. Happy coding!

3
Subscribe to my newsletter

Read articles from Akshay Kamble directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Akshay Kamble
Akshay Kamble