Virtualenv in Python Flashcards

1
Q

What is virtualenv

A

What is:

virtualenv is a tool to create isolated Python environments, it is the

easest way to configure a custom Python environment

It allows you to add and modify Python modules without access to the

global installation

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

What does virtualenv do

A

It addresses one problem of dependencies and versions and indirectly permissions. Practically, we all face these problems:

  1. Looking for a way to configure different versions of libraries to

different application. It is not advisable to install each version in

to you library. For an application, any small changes in its

supportive library will break the application

  1. We cannot install the desired library into the site-packages path

without root.

Virtualenv can solve such problems. Virtualenv has a favorable feature that it creates an enviroment that has its own installation directories which doesn’t share libraries with other virtualenv environments. Namely, connect corresponding environment to corresponding application

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

virtualenv directory-name –no-site-packages

what is the option –no-site-packages in this expression

A

–no-site-packages option will tell virtualenv that the sys.path will not include site packages but everything else will remain there

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

How to use virtualenv

A

run virtualenv env_name

env_name/lib/ and env_name/include/ are created, anything

installed will be under env_name/lib/pythonX.X/site-packages

add #!/path/to/env_name/bin/python to the scripts

pip is also installed isolatedly

Note: many things in this isolated environment are just links to the systemwide python.

run source bin/activate

This will change $PATH so its first entry is the virtualenv’s bin/

If you run python in the env_name/bin/python, you dont have to use

source command

To undo the PATH changes, you just run deactivate

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

The –system-site-packages option

A

–system-site-packages will make your lib inherit the systemwide site-packages. If you want an isolated environment, you should not use the option.

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