Ubuntu/Linux Installation command and
steps
This document describes how to install Python 3.6 or 3.8 on Ubuntu Linux machines.
To see which version of Python 3 you have installed, open a command prompt and run
$ python3 --version
If you are using Ubuntu 16.10 or newer, then you can easily install Python 3.6 with the
following commands:
$ sudo apt-get update
$ sudo apt-get install python3.6
If you’re using another version of Ubuntu (e.g. the latest LTS release) or you want to use
a more current Python, we recommend using the deadsnakes PPA to install Python 3.8:
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.8
If you are using other Linux distribution, chances are you already have Python 3 pre-
installed as well. If not, use your distribution’s package manager. For example on
Fedora, you would use dnf:
$ sudo dnf install python3
Note that if the version of the python3 package is not recent enough for you, there may
be ways of installing more recent versions as well, depending on you distribution. For
example installing the python3.9 package on Fedora 32 to get Python 3.9. If you are a
Fedora user, you might want to read about multiple Python versions available in Fedora.
Working with Python 3
At this point, you may have system Python 2.7 available as well.
$ python
This might launch the Python 2 interpreter.
$ python3
This will always launch the Python 3 interpreter.
Setuptools & Pip
The two most crucial third-party Python packages are setuptools and pip.
Once installed, you can download, install and uninstall any compliant Python software
product with a single command. It also enables you to add this network installation
capability to your own Python software with very little work.
Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip by
default.
To see if pip is installed, open a command prompt and run
$ command -v pip
To install pip, follow the official pip installation guide - this will automatically install the
latest version of setuptools.
Note that on some Linux distributions including Ubuntu and Fedora the pip command
is meant for Python 2, while the pip3 command is meant for Python 3.
$ command -v pip3
However, when using virtual environments (described below), you don’t need to care
about that.
How to install virtualenv:
Install pip first
sudo apt-get install python3-pip
Then install virtualenv using pip3
sudo pip3 install virtualenv
Now create a virtual environment
virtualenv venv
you can use any name insted of venv
You can also use a Python interpreter of your choice
virtualenv -p /usr/bin/python2.7 venv
Active your virtual environment:
source venv/bin/activate
Using fish shell:
source venv/bin/activate.fish
To deactivate:
deactivate
Create virtualenv using Python3
virtualenv -p python3 myenv
Instead of using virtualenv you can use this command in Python3
python3 -m venv myenv
Create VE
Let’s create a virtual environment called “cv4” that uses python3
mkvirtualenv cv4 -p python3
DONE! Just write “workon cv4” whenever you want to activate this
environment.
Basics
From the terminal, run the following commands to update packages and install some
essential software:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential cmake g++ gfortran git vim pkg-config python-dev software-
properties-common wget
sudo apt-get autoremove
sudo rm -rf /var/lib/apt/lists/*
To check version of the opencv2: cv2.__version__
To install specific version of the torch:
pip install torch==1.2.0
pip install torchvision==0.4.0
To Reboot: nvcc -V
Check Nvidia: nvidia-smi
Different Libraries:
1. Pip Install Python libraries
2. Note: we’ll be using tensorflow1.14.0
3. pip install numpy
4. pip install pandas scipy matplotlib pillow
5. pip install scikit-learn scikit-image
6. pip install tensorflow-gpu==1.14.0
7. pip install keras
8. pip install imutils h5py requests progressbar2
Installing OpenCV-Python from Pre-built Binaries
This method serves best when using just for programming and developing OpenCV applications.
Install package python-opencv with following command in terminal (as root user).
$ sudo apt-get install python-opencv
How to know if the installation worked:
In your virtual environment, open python and write
python
import tensorflow as tf
tf.test.is_gpu_available()
tf.test.is_built_with_cuda()
to show how to know Graphics information and details:
$ lspci -nnk | grep VGA -A1
Use this link for further information:
https://medium.com/@dun.chwong/the-ultimate-guide-ubuntu-
18-04-37bae511efb0
How to make VE in Linux:
Let’s start by installing the python3-venv package that provides
the venv module.
1- sudo apt install python3-venv
2- Once the module is installed we are ready to create virtual environments for Python 3.
Switch to the directory where you would like to store your Python 3 virtual environments. Within the
directory run the following command to create your new virtual environment:
python3 -m venv my-project-env
3- The command above creates a directory called my-project-env , which contains a copy of the
Python binary, the Pip package manager, the standard Python library and other supporting files.
To start using this virtual environment, you need to activate it by running the activate script:
source my-project-env/bin/activate
4- Once activated, the virtual environment’s bin directory will be added at the beginning of
the $PATH variable. Also your shell’s prompt will change and it will show the name of the virtual
environment you’re currently using. In our case that is my-project-env :
$ source my-project-env/bin/activate
(my-project-env) $
Now that the virtual environment is activated, we can start installing, upgrading,
and removing packages using pip.
Nvidia Drivers
You will need to download the correct driver based on your GPU model,
which you can check with the following command:
lspci | grep -i nvidia
Check the Proprietary GPU Drivers PPA repository to find the current release
for your GPU. As of the time of this writing the latest release for the GeForce
10 Series is 381.22, however I opted to go with the 375.66 — the current long-
lived branch release. Install the driver with the following commands:
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-375
Then restart your computer:
sudo shutdown -r now
To double check that the driver has installed correctly:
cat /proc/driver/nvidia/version
CUDA
Download the CUDA 8.0 toolkit from Nvidia’s site. Go to the Downloads
directory (or where ever you chose to save it) and install CUDA:
sudo dpkg -i cuda-repo-ubuntu1604*amd64.deb
sudo apt-get update
sudo apt-get install cuda
Add CUDA to the environment variables:
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
Check that the correct version of CUDA is installed:
nvcc -V
Restart your computer:
sudo shutdown -r now
How to Clone and make GITHUB directory:
Step 1: Set up a GitHub Account
If you haven’t done so already, make a Github.com account, it’s free! This is where you’ll be creating a
repo and putting in files. Once you’re in your GitHub account, click Create a repository (or New
Repository), which will take you to a page where you can add details for your repo.
Step 2: Create a Repo
Fill out the details for your repo and be sure to take note your repo name, you’ll need it later in this
tutorial. If you are curious about the options on this screen, the README file is common for writing
instructions to your users. The licensing option can seem confusing but if you are questioning which
one to choose you can check out this site to guide you. Once all details are in, click Create repository.
Once created, you’ll see two files in your repository if you chose the licensing and README file.
Step 3: Configuring Git per User
After installing Git, configuration is needed for commit messages to be sent out. Without setting the
name and email address you’ll see warnings when making commitments to git. If you have multiple
user who utilize git, make an entry for each user. You can easily set these details for a user with two
commands within your server’s terminal. (If you need to access the information set you can find it in
the .gitconfig file.)
Note:
If you already have a github.com account you can use the associated username and email.
git config --global user.name "Your_Name"
git config --global user.email "email_address@domain.com"
Step 4: Create A Directory
When you create a directory, you can use this space to sync newly written/edited code to your GitHub
account. I’m going to call this environment git_environment and move into the directory using the cd
command.
mkdir git_environment
cd git_environment
Step 5: Copy your GitHub URL
First, its necessary to clone or download our already pre-existing README and licensing file from our
GitHub account. Jump back to your GitHub account, click Clone or download and copy your GitHub
link.
Step 6: Clone your Repo
In your terminal, you should find yourself in the GitHub directory. We will first clone our repo with
our copied GitHub URL and then change directories to our project name.
git clone https://github.com/username/want-some-java.git
cd want-some-java
By listing the want-some-java directory, you’ll see the two files in your repo, verifying that the
cloning has worked.
ls
Example Output:LICENSE README.md
In our next tutorial, where will teach you how to edit/create a file on your server and push the script to
your GitHub account.
Install Github on Ubuntu
Step 1- Create a Github account
To install github on Ubuntu, first we need to have a Github account. To create one
goto Official Github Page , next you need to fill the form to create the account,
Mention a username, email address & password to create the account. Once we have
created the account, we will move onto next step.
Step 2:- Install Git on the system
Next step is to get the Git packages installed onto our system. Git packages are available
with the default repositories on Ubuntu, so we don’t have to install any additional repos &
we can simply install all the Git packages using the following command,
$ sudo apt-get install git-core git-gui git-doc
We are now ready to configure the github on our system & there are two using which we
can use github on our system i.e. either using ‘http’ or accessing github using ‘ssh’ . We will
discuss both process one by one.
Step 3A- Using HTTP for connection
For this method, we will start by configuring the username & email-address on git that we
have used for Github. To configure the username, execute the following command from
terminal,
$ git config --global user.name “linuxtechlab”
Replace “linuxtechlab” with your username. Next to configure the email address for git, use
the following command,
$ git config --global user.email “admin@linuxtechlab.com”
Now, create a directory on your system for cloning the Github repository,
$ mkdir /home/linuxtechlab/git_repo
Make the directory git ready by running following command,
$ cd /home/linuxtechlab/git_repo
$ git init
Now we can clone the repo from github, use the following command,
$ git clone
Again, replace linuxtechlab/testproject.git with your username & project name. Next you
will asked to enter the username & password for Github, as soon as we do so cloning will
start.
We can than perform other Git related operations. If you need list of Git commands for
reference, you can use the following tutorial Complete “Beginners to PRO” guide for
GIT commands.
Step 3B – Using SSH for connection
For this method, we will start by creating Public/Private SSH keys also known as ‘ssh key
pair’. Create the key using the following method,
$ cd ~/.ssh
Note:- If the following folder does not exist, than create it.
To create key pair, use the command,
$ ssh-keygen -t rsa -C "your_email@youremail.com"
Once you hit enter you will be asked a bunch of options, you can hit enter to use the default
values for all (unless you want to modify something). So we now have our ssh key pair. For
next step we would the public key, it should be named as “id_rsa.pub” (unless you have
modified the name, in that case look for file with .pub extension).
Open the public key file & copy the content of the file. Now head over to web browser,
where you are logged into the github account. We need to goto,
Account Settings → SSH Keys → Add another public key
Now paste the copied content of public key into the ‘key’ field & than press ‘Add key’.
Now head back to terminal on Ubuntu & run the following command,
$ ssh-add
That’s it, we can now start the cloning on our system. As we did above, first create a folder
for cloning the repository, make it git ready & than start the cloning,
$ mkdir /home/linuxtechlab/git_repo
$ git init
$ git clone git@github.com:username/projectname.git
That’s it for this tutorial on how to install Github on Ubuntu. Feel free to reach to us using
the comment box below for any question or suggestion.
How to Install Pip on Ubuntu 18.04
Updated
4 min read
Pip is a package management system that simplifies installation and management of software
packages written in Python such as those found in the Python Package Index (PyPI). Pip is not
installed by default on Ubuntu 18.04, but the installation is pretty straightforward.
In this tutorial, we will show you how to install Python Pip on Ubuntu 18.04 using the apt package
manager. We will also walk you through the basics of installing and managing Python packages with
pip.
Prerequisites
Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges .
Installing pip for Python 3
Ubuntu 18.04 ships with Python 3, as the default Python installation. Complete the following steps to
install pip (pip3) for Python 3:
1. Start by updating the package list using the following command:
sudo apt update
2. Use the following command to install pip for Python 3:
sudo apt install python3-pip
The command above will also install all the dependencies required for building Python
modules.
3. Once the installation is complete, verify the installation by checking the pip version:
pip3 --version
The version number may vary, but it will look something like this:
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)