Python Virtual Environment and Linux User Management

Data Science with Keshav - Lesson 1: Preparing Your Flight

Hello, and welcome to Lesson 1 of my tutorial series, “Data Science with Keshav“. To get an overview of what this tutorial series is about, you can check out my another post, Data Science 101. In this part of this tutorial series, you will learn the basics of user management and learn how to use python virtual environment. If you are on Windows Operating System, you can skip the user management section and jump directly to set up and use virtual environment. We will be using python version 3.5 on Ubuntu 16.04 for this tutorial series.

1. User Management

First of all, why do we need user management? Linux is a multi-user OS. Different users can have different requirements and different roles, according to which administrator provides different sets of permission and access. All these task of creating various users and providing them with necessary privileges come under user management. We won’t cover all of this in detail however, I will show how we can manage users in basic level. The commands for various user management related tasks are as:

  • Add User

$ sudo adduser newuser

  • Show User Groups

$ groups newuser

  • Assign User to a Group

$ usermod -aG sudo newuser

  • Specifying Explicit User Privileges in /etc/sudoers

$ sudo visudo

And, add this Line

newuser ALL=(ALL:ALL) ALL

  • Delete User without deleting user’s home directory

$    sudo deluser newuser

  • Delete User and delete user’s home directory

$    sudo deluser –remove-home newuser

  • Remove all of the files for the user

$    sudo userdel -r newuser

  • Removing user privileges

$    sudo visudo

And, delete this Line

newuser ALL=(ALL:ALL) ALL   # DELETE THIS LINE

2. Python Virtual Environment

Those were the basic commands for user management. Now let turn our attention towards python virtual environment. Starting with, why do we need virtual environment in the first place? Python programs often use packages and modules that don’t come as part of the standard library. These packages may have several release versions. So, quite often we might find ourselves in situations where one of the running applications might need a package of one version while the other needs the same package but of a different version. This will lead to conflicts. To solve this conflict, we need python virtual environment. For a detailed documentation on python virtual environments, you can check python’s official documentation. Here, we are only going to discuss what we need for this tutorial series. So, let’s jump into the implementation.

  • Install virtualenv

$    pip3 install virtualenv

In case you have any error regarding superuser you can try

$    sudo -H pip3 install virtualenv

  • Creating virtual environments

$    virtualenv envs

Note:  You can have several choices of making virtual environment, you can try virtualenv –help to see more in detail

  • Activate virtualenv envs

$    source ~/envs/bin/activate

  • Deactivate envs

(envs) $    deactivate

  • Removing envs

$    sudo rm -rf ~/envs

Note: Here I have assumed you are in the home directory, but you can also create a virtual environment in other directories you want. For eg: 

~/Desktop/DeskDir$ virtualenv deskVir

Above code will create virtualenv in deskVir directory in desktop.

To check the part 3 of my tutorial series, “Diving into world of Data Science, Technology and Discussion“, you can follow this link here.

 

About Keshav Bhandari 6 Articles
Deel Learning Enthusiast. PhD Student at Texas State University.

4 Trackbacks & Pingbacks

  1. Learn Data Science, Data Science 101 | Python 3.6
  2. MNIST Handwritten digits classification using Keras (part – 1) | Python 3.6TrendGlobe | TrendGlobe
  3. MNIST Handwritten digits classification using Keras (part - 1) | Python 3.6 | Softwares Bloggers | Softwares Reviews | Best Online Softwares
  4. Fifa worldcup 2018 Round of 16 flag detection using CNN | Python 3.6

Leave a Reply

Your email address will not be published.




This site uses Akismet to reduce spam. Learn how your comment data is processed.