[PYTHON] Virtual Environment `virtualenv`

justwriteit.·2023년 1월 21일
1

python.log

목록 보기
1/1
post-thumbnail

GOAL

The goal is to install the virtualenv module to have each of the workspaces to run in their own virtual environment.
According to the official documents, "virtualenv is used to manage Python packages for different projects."

💡 WHY SHOULD I USE virtualenv?
Well, using it helps you become more organized. Each of your projects might need different versions of python libraries. Having virtual environments for each of them therefore would be helpful in being more productive.

ENVIRONMENT

I am working on the Visual Studio Code on Windows 10:
- Python 3.11.1
- pip 22.3.1

STEP 1. Install virtualenv module

Install the module with the following code:

py -m pip install --user virtualenv

💡 Since Python 3.3, venv package is shipped together with the python itself and it serves the same purpose as virtualvenv. However it only has a subset of features. You can find more int he official document here. It seems that virtualenv is still the more popular one as it supports both Python 2 and 3, so I think I'll keep to it for now.

STEP 2. Create a virtual environment

Create the virtual environment in a workspace using the following code:

py -m venv env
# env is the location to create the virtual environment

STEP 3. Activate the virtual environment

Activate the virtual environment in the workspace using the following code:

.\env\Scripts\activate
# env here refers to the location where you created the virtual environment (refer to step 2)

STEP 4. Deactivate

Deactivating is easy:

deactivate

Hoorah.

RESOURCE

https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/
https://stackoverflow.com/questions/41573587/what-is-the-difference-between-venv-pyvenv-pyenv-virtualenv-virtualenvwrappe
https://towardsdatascience.com/why-you-should-use-a-virtual-environment-for-every-python-project-c17dab3b0fd0

profile
my records

0개의 댓글