Environments Flashcards

1
Q

How to show all installed libraries in a given environment?

A

>> pip freeze

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

How to create a new virtual environment in Python without using conda/anaconda?

A

>> python -m venv [name of the desired environment]

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

How to activate a particular virtual environment in Mac/Linux?

A

>>> source /env/bin activate

Creating a venv in Python automatically creates a folder with files, including a bin file. Use the path to this folder in the command above.

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

How to know if I am using a venv that I created, for example, one named venv1?

A

If I have activated the venv correctly, the command prompt line will include the name of the env like shown below:

>>> (venv1) [user][directory name] %

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

How to compile a list of all installed modules into a .txt file?

A

>>> pip freeze > file_name.txt

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

How to make sure I install all the modules needed for a program given a .txt file? For example, assume that the file is called requirements.

A

>>> pip install -r requirements.txt

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

What is a virtual environment?

A

The virtual environment act as a container for all the necessary modules/libraries needed for the program to run as intended by the developer. This container enables the code to be run on other machines regardless of their current configuration.

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

Why do developers use virtual enviroments when creating programs in Python?

A
  1. The target machine, which will run the program, might not necessarily have the same modules and/or the same versions of the modules that the developer used while creating the program. In some cases, this deviation might render the program useless.
  2. A virtual environment (venv) allows the developer to adjust modules and their versions to the program without affecting the rest of the machine. If the dev were to update a module without using a venv, it could potentially wreak havoc on other unrelated programs that rely on a specific version of a module to work properly.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

After creating a virtual enviroment, where shoud I put the file that constitute the program?

A

It is good practice to create a separate folder to contain the code for the program, for example, creating an src folder. It is not advised to store these files in the same folder as the files that define the venv.

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

How to deactivate a virtual environment after I am done developing?

A

>>> deactivate

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

How to install a given module, for example, the pandas library?

A

>>> pip install pandas

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

What are the possible ways of installing a package?

A
  1. Use pip
  2. Install from a third-party file
  3. Install from a GitHub repository
  1. >>> pip install python-dateutil
  2. >>> cd python3 -m pip install or >>> python3 -m pip install package.tar.gz
  3. >>> git+https://github.com/your-repo.git
How well did you know this?
1
Not at all
2
3
4
5
Perfectly