Category Archives: Ubuntu

Install different python versions with virtualenvwrapper

Sometimes we need to install different version of virtual environments in same machine.

Check this post for create virtual environment in Ubuntu 16.04.

First you need to install different python versions in your machine.

Ubuntu 14.04 and 16.04

If you are using Ubuntu 14.04 or 16.04, you can use J Fernyhough’s PPA:

sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6

Alternatively, you use Felix Krull’s deadsnakes PPA:

sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python3.6
Ubuntu 16.10 and 17.04

If you are using Ubuntu 16.10 or 17.04, then Python 3.6 is in the universe repository, so you can just run

sudo apt-get update
sudo apt-get install python3.6

Then you need to create virtual environment with specific python environment.

mkvirtualenv -p /usr/bin/python3.6 python_3.6

This will install python 3.6 in your machine.

Happy Coding 🙂

Advertisements

Create virtual environment with virtualenvwrapper in Ubuntu 16.04

Suppose you need to work on three different projects project A, project B and project C. project A and project B need python 3 and some required libraries. But for project C you need python 2.7 and dependent libraries.

So best practice for this is to seperate those project environemtns. To create virtual environment you can use below technique:

  1. Virtualenv: Virtualenv is a tool to create isolated Python environments.
  2. Virtualenvwrapper: While virtual environments certainly solve some big problems with package management, they’re not perfect. After creating a few environments, you’ll start to see that they create some problems of their own, most of which revolve around managing the environments themselves. To help with this, the virtualenvwrapper tool was created, which is just some wrapper scripts around the main virtualenv tool.A few of the more useful features of virtualenvwrapper are that it:- Organizes all of your virtual environments in one location;
    – Provides methods to help you easily create, delete, and copy environments; and,
    – Provides a single command to switch between environments
  3. Conda: Conda is a package manager application that quickly installs, runs, and updates packages and their dependencies. Conda is also an environment manager application. A conda environment is a directory that contains a specific collection of conda packages that you have installed.

Continue reading Create virtual environment with virtualenvwrapper in Ubuntu 16.04

SFTP Command to Transfer Files on Remote Servers

SSH File Transfer Protocol, a network protocol used for secure file transfer over secure shell.

SFTP (Secure File Transfer Protocol) runs over SSH protocol on standard port 22 by default to establish a secure connection. SFTP has been integrated into many GUI tools (FileZilla, WinSCP, FireFTP etc.).

Below are the most used commands for SFTP:

1. Connect to SFTP

To connect with SFTP we can use below commands.

[root@salayhin ~]# sftp salayhin@20.42.230.5

Connecting to 20.42.230.5...
tecmint@20.42.230.5's password:
sftp>

If we are using AWS we can add the pem file location with this command.

[root@salayhin ~]# sftp -i PemFile.pem salayhin@20.42.230.5

Continue reading SFTP Command to Transfer Files on Remote Servers

Python locale error: unsupported locale setting

Sometimes we are getting local error and cannot install packages via pip.

I found a solution to get rid of it.

Run this command from your command line interface.

$ export LC_ALL=C

Output from locale is:

$ locale
LANG=co404
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=C

Mysql ‘Got error -1 from storage engine’ error

Today I got an error while updating my mysql record . I got “Mysql ‘Got error -1 from storage engine’ error” every time I try to update.

Below are the logs I found from my mysql error logs:

MySQL Error log path: /var/log/mysql/error.log

InnoDB: A new raw disk partition was initialized or
InnoDB: innodb_force_recovery is on: we do not allow
InnoDB: database modifications by the user. Shut down
InnoDB: mysqld and edit my.cnf so that newraw is replaced
InnoDB: with raw, and innodb_force_... is removed.

Finally I got solution for that. To solve this issue follow below steps.

1. Stop your mysql server

 sudo service mysql stop 

2. Set innodb_force_recovery to 0 or remove this line from /etc/mysql/my.cnf

 innodb_force_recovery = 0 

3. Start your mysql server

 sudo service mysql start 

This will solve your problem.

Happy Coding 🙂

vi – basic commands

vi is a screen-oriented text editor originally created for the Unix operating system.

Basic commands:

To Start vi:

* vi filename Create or Edit filename starting at line 1
* vi -r filename Recover filename that was being edited 

To Exit vi:

* :x<return> Quit vi, writing out modified file to file named in original invocation
* :wq<return> Quit vi, writing out modified file to file named in original invocation
* :q<return> Quit or exit vi
* :q!<return> Quit vi even though latest changes have not 

Moving the cursor:

* j or <return> [or down-arrow] Move cursor down one line
* k[or up-arrow] Move cursor up one line
* h or<backspace> [or left-arrow]

Move cursor left one line:

* l or<space>[or right-arrow] Move cursor right one line
* 0(zero) Move cursor to start of current line(the one with the arrow)
* $ Move cursor to end of the current line
* w Move cursor to beginning of next word Basic vi commands7. b Move cursor back to beginning of preceding word
* :0<return> or 1G Move cursor to first line in file
* :n<return>or nG Move cursor to line n in file
* :$<return>or G Move cursor to last line in file

Screen Manipulation:

* ^f Move forward one screen
* ^b Move backward one screen
* ^d Move down(forward) one half screen
* ^u Move up(back)one half sreen
* ^l Redraws the screen
* ^r Redraws the screen,removing the deleted lines 

Adding,Changing,Deleting the text:

* u Undo whatever you just did(a simple toggle)

Inserting or Adding text:

* i Insert text before cursor,until<esc>hit
* I Insert text at beginning of current line,until<esc>hit
* a Append text after cursor,until<esc>hit
* A Append text to end of current line,until<esc>hit
* o Open and put text in a new line below current line,until<esc>hit
* O Open and put text in a new line above current line,until<esc>hit

Basic vi commandsChanging the text:

* r Replace single character under cursor(no <esc>needed)
* R Replace characters,starting with current cursor position,until<esc>hit
* cw Change the current word with new text,starting with the character under cursor,until<esc>hit
* cNw Change N words beginning with the character under cursor,until<esc>hit
* c change(replace)the characters in the current line,until<esc>hit
* cc change(replace)the characters in the current line,stopping when <esc>hit
* Ncc or cNc change(replace)the next N lines,starting with the current line,stopping when <esc>hit

Deleting the text:

* x Delete single character under cursor
* Nx Delete N characters, starting with character under cursor
* dw Delete the single word beginning with character under cursor
* dNw Delete N words beginning with character under cursor
* D Delete the remainder of the line,starting with current cursor position
* dd Delete entire current line
* Ndd or dNd Delete N lines beginning with the current line

Basic vi commandsCutting and pasting the text:

* yy Copy (yank,cut) the current line into buffer
* Nyy or yNy copy(yank,cut) the next N lines,including the current line, into the buffer
* p put(paste) the lines in the buffer into the text after the current line

Searching the text:

* /string Search forward for occurence of string in text
* ?string Search backward for occurence of string in text
* n Move to next occurence of search string
* N Move to next occurence of search string in opposite direction

Determining line numbers:

* :.= Returns line number of current line at bottom of screen
* := Returns the total number of lines at bottom of the screen
* ^g Provides the current line number, along with the total number of lines,in the file at the bottom of the screen

Saving and reading files:

* :r filename<return> Read file named filename and insert after current line(the line with arrow) Basic vi commands2. :w<return> Write current contents to a file named in original vi call
* :w newfile<return> Write current contents to a new file named newfile
* :12,35w smallfile<return> Write the contents of the line numbered 12 through 35 to a new file named smallfile
* :w! prevfile<return> Write current contents over a pre-existing file named prevfile