How To Create Virtual Environment In Python In Current Directory
To activate a virtual environment for Python in the current directory, you can use the virtualenv
package. This package allows you to create isolated Python environments, which can be useful for managing dependencies and installing specific versions of packages.
To install virtualenv
, you can use the following command:
pip install virtualenv
Once you have installed virtualenv
, you can create a new virtual environment in the current directory by running the following command:
virtualenv env
This will create a new directory called env
in your current directory, which contains the files and directories for your new virtual environment.
To activate your virtual environment, you can use the following command:
source env/bin/activate
This will modify your shell prompt to indicate that you are now using the virtual environment. You can now use pip
to install packages in your virtual environment without affecting the global Python installation.
When you are finished using your virtual environment and want to return to the global Python installation, you can use the deactivate
command:
deactivate
This will return your shell prompt to its normal state and you will no longer be using the virtual environment.
Responses