Dayalan Saravanan


Creating a virtual environment in Python:

In Python 3.6+, the recommended way to create a virtual environment is to run:

$ python3 -m venv /path/to/new/virtual/environment

Make sure that python3 resolves to whichever version of python3 you'd like to bind to your virtual environment. For example, to create a new virtual environment named dsci in your home directory, you could run:

$ python3 -m venv ~/dsci

To activate a virtual environment on macOS or Linux running bash or zsh, source the following path:

$ source ~/dsci/bin/activate

and for deactivation:

$ deactivate

Managing packages with pip:

$ pip search <pkg_name>
$ pip show <pkg_name>
$ pip install <pkg_name>
$ pip install <pkg_name == version_number>
$ pip install --upgrade <pkg_name>
$ pip list
$ pip freeze > requirements.txt
$ pip install -r requirements.txt

Namespaces and Variable Scoping

When you type the name of a variable inside a script or interactive python session, python needs to figure out exactly what variable you're using. To prevent variables you create from overwriting or interfering with variables in python itself or in the modules you use, python uses the concept of multiple namespaces. Basically, this means that the same variable name can be used in different parts of a program without fear of destroying the value of a variable you're not concerned with.

To keep its bookkeeping in order, python enforces what is known as the LGB rule. First, the local namespace is searched, then the global namespace, then the namespace of python built-in functions and variables. A local namespace is automatically created whenever you write a function, or a module containing any of functions, class definitions, or methods. The global namespace consists primarily of the variables you create as part of the "top-level" program, like a script or an interactive session. Finally, the built-in namespace consists of the objects which are part of python's core. You can see the contents of any of the namespaces by using the dir command:

>>> dir()
>>> dir(__builtins__)

The __builtins__ namespace contains all the functions, variables and exceptions which are part of python's core.

Installing R in Debian 10 and add packages from the CRAN
Installing Python in Debian 12 GNU/Linux
Installing Node.js in Debian 10 GNU/Linux
Installing Nvidia drivers and the CUDA toolkit in Ubuntu 20.04
Scipy Lecture Notes - numerics, science, and data
Customize the color of text in IPython
Installing Mayavi on Ubuntu 20.04
Instructions for installing Julia in Debian 10 GNU/Linux
A list of modern colors
Vim Reference
Git Reference
Programming Fonts - Test Drive