How do you manage python environments using venv? (AI) Flashcards

(10 cards)

1
Q

What is venv and why is it used?

A

venv (virtual environment) is a standard Python module used to create isolated environments for Python projects. It prevents dependency conflicts between projects by installing packages locally.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the standard command to create a new virtual environment named my_env?

A

python3 -m venv my_env (or just python -m venv my_env on some systems). This creates the my_env directory containing a copy of the Python interpreter and support files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the command to activate an environment named my_env on Linux/macOS?

A

source my_env/bin/activate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the command to activate an environment named my_env on Windows (Command Prompt/PowerShell)?

A

Command Prompt: my_env\Scripts\activate.bat<br></br>PowerShell: my_env\Scripts\Activate.ps1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you know a virtual environment is active?

A

The name of the active environment (e.g., (my_env)) is prepended to your shell prompt.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Once an environment is active, what does the pip install command do?

A

pip install installs packages only into the active virtual environment, not globally on your system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the command to deactivate the currently active virtual environment?

A

deactivate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

If you delete the my_env directory while the environment is inactive, what happens?

A

The environment is permanently deleted. There is no need for a special “uninstall” command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What command do you use to share a list of installed packages from your active environment with others?

A

pip freeze > requirements.txt (This creates a file listing all exact package versions.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What command is used to install all dependencies listed in a requirements.txt file into an active environment?

A

pip install -r requirements.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly