You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

已安装virtualenv后如何在Windows系统的Python中激活虚拟环境?

How to Activate virtualenv on Windows (When It’s Already Installed)

Hey there! Since virtualenv is already set up on your Windows system, you just need to create a virtual environment first before activating it. Let’s walk through the process step by step:

Step 1: Open Terminal and Navigate to Your Project Folder

Launch either Command Prompt (CMD) or PowerShell, then use the cd command to move to the directory where you want to set up your isolated environment. For example:

cd C:\Users\Dell PC\Documents\MyPythonProject

Step 2: Create a Virtual Environment

Run this command to generate a new virtual environment (you can replace venv with any name you like, such as my_dev_env):

virtualenv venv

This will create a folder named venv (or your custom name) in your project directory, containing a standalone Python environment.

Step 3: Activate the Virtual Environment

The activation command varies a bit based on which terminal you’re using:

  • In Command Prompt (CMD):
    venv\Scripts\activate.bat
    
  • In PowerShell:
    venv\Scripts\Activate.ps1
    

Fix PowerShell Script Execution Errors

If PowerShell blocks the activation script with a "execution disabled" error, run this command first (press Y when prompted to confirm):

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

This lets your user account safely run local scripts without affecting system-wide settings.

Confirm Activation

Once activated, you’ll see your virtual environment’s name in parentheses at the start of your terminal prompt (like (venv)), which means you’re now working in the isolated Python environment.

To Exit the Virtual Environment

When you’re done with your work, just run this command to deactivate:

deactivate

内容的提问来源于stack exchange,提问作者Didi

火山引擎 最新活动