Skip to content

Latest commit

 

History

History
79 lines (73 loc) · 3.1 KB

File metadata and controls

79 lines (73 loc) · 3.1 KB

diagram-export-4-7-2025-4_50_24-AM

Here are five methods to create and manage Python virtual environments:

  1. uv:

    • Installation: uv is a fast Python package installer that can also manage virtual environments.
    • Creating a Virtual Environment: To create a virtual environment using uv, navigate to your project directory and run:
      uv venv
      This command creates a virtual environment in the current directory. citeturn0search5
    • Activating the Virtual Environment: Activation is not required with uv. You can run commands directly within the virtual environment using:
      uv pip install <package_name>
      This installs packages into the uv-managed virtual environment. citeturn0search5
  2. venv:

    • Installation: venv is included in the Python standard library for versions 3.3 and above.
    • Creating a Virtual Environment: Navigate to your project directory and run:
      python -m venv venv
      This creates a .venv directory containing the virtual environment. citeturn0search2
    • Activating the Virtual Environment:
      • On macOS/Linux:
        source venv/bin/activate
      • On Windows:
        .venv\Scripts\activate
      Once activated, you can install packages using pip.
  3. Pipenv:

    • Installation: Install Pipenv using pip:
      pip install pipenv
    • Creating a Virtual Environment: In your project directory, run:
      pipenv install
      This creates a Pipfile and a virtual environment. citeturn0search1
    • Activating the Virtual Environment: To activate the environment, run:
      pipenv shell
      You can install packages using pipenv install <package_name>.
  4. Poetry:

    • Installation: Install Poetry using the recommended installation script:
      curl -sSL https://install.python-poetry.org | python3 -
    • Creating a Virtual Environment: In your project directory, initialize a new project:
      poetry init
      This sets up a pyproject.toml file. citeturn0search14
    • Activating the Virtual Environment: Poetry automatically manages virtual environments. To activate it, use:
      poetry shell
      Install packages with poetry add <package_name>.
  5. Conda:

    • Installation: Download and install Anaconda or Miniconda from the official website.
    • Creating a Virtual Environment: Create a new environment named myenv with Python:
      conda create -p venv python==3.** -y
      This sets up a new environment with the specified Python version. citeturn0search28
    • Activating the Virtual Environment: Activate the environment using:
      conda activate myenv
      Install packages using conda install <package_name>.