Python Virtual Environments with Virtualenvwrapper on Windows
2024.02.23 12:20浏览量:5简介:Virtualenvwrapper is a wrapper around virtualenv that provides an easy way to create, switch, and manage multiple virtual environments. In this article, we will guide you through the process of setting up virtualenvwrapper on Windows.
千帆应用开发平台“智能体Pro”全新上线 限时免费体验
面向慢思考场景,支持低代码配置的方式创建“智能体Pro”应用
- Installing Virtualenvwrapper
To install virtualenvwrapper on Windows, you need to have Python and pip installed first. Once you have confirmed that they are properly installed, you can proceed with the installation.
Open a command prompt or PowerShell window and run the following command to install virtualenvwrapper:
pip install virtualenvwrapper-win
This will install virtualenvwrapper and its dependencies.
- Configuring Virtual Environments
To configure virtual environments, you need to set up a few environment variables. Open the ‘System Properties’ dialog by clicking on ‘My Computer’ in the desktop menu, right-clicking, and selecting ‘Properties’. Then click on the ‘Advanced’ tab and click on ‘Environment Variables’.
In the ‘System variables’ section, click ‘New’ and add the following variables:
Variable Name: WORKON_HOME
Variable Value: The path where you want to store your virtual environments (e.g., ‘C:\Users\YourUsername\Envs’)
Click ‘OK’ to save the variable.
Next, find the ‘Path’ variable in either the ‘System variables’ or ‘User variables’ section (depending on whether you want the virtualenvwrapper to be available system-wide or just for the current user) and append ‘;%WORKON_HOME%\bin’ to the end of the value.
Click ‘OK’ to save the changes.
- Creating a Virtual Environment
Now that the virtualenvwrapper is set up, you can create a new virtual environment. Open a command prompt or PowerShell window and run the following command:
mkvirtualenv myenv
This will create a new virtual environment called ‘myenv’. You can replace ‘myenv’ with the name of your choice.
- Activate the Virtual Environment
To start using the virtual environment, you need to activate it. Run the following command:
workon myenv
Replace ‘myenv’ with the name of your virtual environment.
This will activate the virtual environment. You can now install packages into this environment using pip without affecting other environments or your system-wide Python installation.
- Deactivate the Virtual Environment
When you are done working in a virtual environment, you can deactivate it by running the following command:
d workon myenv
Replace ‘myenv’ with the name of your virtual environment.
This will deactivate the virtual environment.
That’s it! You have successfully set up virtualenvwrapper on Windows and can now create, switch, and manage multiple virtual environments for your Python projects.

发表评论
登录后可评论,请前往 登录 或 注册