Install Operation System Ubuntu 14.04 and Some Softwares

Recently I was working with postgresql and python on Ubuntu. When I need to use pl/python extension, I met a system error but I cannot know how to fix it directly. Then a simple idea just came into my mind: reinstall the operation system and all the softwares.

本文方法也基本适用其他版本的ubuntu。自从装了16以来,bug不断,还是决定重回14了。被自己的强迫症打脸了。 在16中碰到的尚未解决的问题包括但不限于: 运行pgadmin3时出现:

Debug: Failed to connect to session manager: SESSION_MANAGER environment variable not defined. Debug: Adding duplicate image handler for ‘PNG file’

最开始只有第二句,后来两句都有了。我在自己的电脑上测试少量数据,删除表格或schema会显示Running,没有任何错误提示,也没有任何会跑完的迹象。 在pgadmin3界面点击一个表格,整个软件就会奔溃。 未找到解决方法。

Install Ubuntu

Go to the official website of Ubuntu to get the latest desktop version. Follow the steps and you’ll get it. If you want previous version like 14.04 LTS, please go as: Downloads - Alternative Downloads - Other Images - See all ubuntu mirrors. And then click http in Shanghai Jiao Tong University, China. The download speed is quite fast.

Prepare a new USB stick

Find Startup Disk Creator in the Software Center. If you find the usb disk cannot be erased, go to Disks software to format it. After you build the usb as a startup disk, it cannot be used to save files any more.

Small problem

{% blockquote %} Missing parameter in configuration file. Keyboard: path gfxboot.c32: not a COM32R image boot: {% endblockquote %}

The bug would appear only when you build a Startup Disk and use it immediately on the same PC.
Just typing Tab and then choosing live or live-install would start the installation.

Open Here in Terminal

This is a very useful add-on called nautilus to help daily usage.

1
sudo apt-get install nautilus-open-terminal

Then restart nautilus to make it work immediately.

1
nautilus -q

Then you’ll find Open in Terminal in your right-click menu list.

Python

Install latest python

Since Ubuntu 14.04 is installed with Python 3.4, let’s install latest python 3.5.2.

Alternative

We need C compiler and other stuff to compile Python

1
sudo apt-get install build-essential

SQLite libs need to be installed in order for Python to have SQLite support.

1
2
3
sudo apt-get install libsqlite3-dev
sudo apt-get install sqlite3 # for the command-line client
sudo apt-get install bzip2 libbz2-dev

Use apt-get install

添加 PPA:

1
2
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update

安装 Python 3.5:

1
2
3
sudo apt-get install python3.5
sudo apt-get install python3.5-dev
sudo apt-get install libncurses5-dev

安装新版pip:

1
2
3
4
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
sudo pip3 install setuptools --upgrade
sudo pip3 install ipython[all]

Reference: 在 Ubuntu 14.04.3 上安装 Python 3.5

Build virtual env of Python

1
2
3
4
5
sudo apt-get install build-essential
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade virtualenv
virtualenv -p /usr/bin/python3.5 /home/katherine/venv/py35
source /home/katherine/venv/py35/bin/activate

Then

1
sudo gedit ~/.bashrc

Add the following code at the bottom of .bashrc file.

1
alias venvpy35='source /home/katherine/venv/py35/bin/activate'

Return to the terminal window.

1
2
source ~/.bashrc
venvpy35

Next time, you don’t need to type the long sentence any more. Instead, type venvpy35 in the terminal and the virtual environment would be activated.

If you want to exit the virtual environment, just type deactivate.

virtualenv cannot be build under sudo, or pip install would not have the access to the site-packages directory of the virtualenv.

Install Mostly-Used Packages

1
2
3
pip3 install pandas
pip3 install psycopg2
pip3 install sqlalchemy==1.1.1

pip-Uninstall Packages with Dependencies

install pip-autoremove

1
pip install pip-autoremove

remove “somepackage” plus its dependencies:

1
pip-autoremove somepackage -y

Reference: pip-uninstall packages with dependencies

Install cx_oracle

Install Dependencies

Activate your virtual environment, and then do the following steps.

1
sudo apt-get install unzip python3.5-dev libaio-dev

建议安装对应版本的python-devpython3.5-dev,否则pip install cx_Oracle会出现错误提示cannot find Python.h

Download Oracle Client

Login oracle website and download:

  • instantclient-basic-linux.x64-12.1.0.2.0.zip
  • instantclient-sdk-linux.x64-12.1.0.2.0.zip
  • instantclient-sqlplus-linux.x64-12.1.0.2.0.zip

Unzip oracle client

1
2
3
4
5
cd
mkdir cx_Oracle
unzip instantclient-basic-linux.x64-12.1.0.2.0.zip -d cx_Oracle
unzip instantclient-sdk-linux.x64-12.1.0.2.0.zip -d cx_Oracle
unzip instantclient-sqlplus-linux.x64-12.1.0.2.0.zip -d cx_Oracle

Set ORACLE_HOME location

1
sudo gedit ~/.bashrc

然后添加以下语句到~/.bashrc,然后保存。这是告诉安装程序oracle安装文件的位置,若后面出现cannot locate oracle installation的提示,一定是这里没有设置好。注意:ORACLE_HOME 要指向绝对路径。

1
2
3
4
# cx_Oracle
export ORACLE_HOME=/home/katherine/cx_Oracle/instantclient_12_1
export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
export PATH=${PATH}:${ORACLE_HOME}

记得更新配置:

1
2
source ~/.bashrc
mypy35

对以下文件建立软链接。

1
2
3
4
cd cx_Oracle/instantclient_12_1
sudo ln -sf libclntsh.so.12.1 libclntsh.so
sudo ln -sf libclntshcore.so.12.1 libclntshcore.so
sudo ln -sf libocci.so.12.1 libocci.so

Install cx_oracle

1
pip3 install cx_Oracle

Reference:

  1. cx_Oracle在virtualenv(python)中的pip安装
  2. cx_Oracle instant client install python3
  3. 在PostgreSQL中使用oracle_fdw访问Orcale(foreigh table)

Install

Install postgresql

Install postgresql

Add PostgreSQL Apt Repository

1
2
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

Install PostgreSQL

1
2
3
sudo apt-get update
sudo apt-get install postgresql-9.5 postgresql-contrib-9.5 postgresql-plpython3-9.5 postgresql-client-9.5 postgresql-common postgresql-server-dev-9.5
sudo apt-get install libpq-dev

Configure PYTHONPATH to PostgreSQL Environment

Add PYTHONPATH='/home/katherine/Documents/Coding/jfds/src:/home/katherine/venv/py352/lib/python3.5/site-packages' to /etc/postgresql/9.5/main/environment.

Then run:

1
sudo service postgresql restart

Initial settings

postgreSQL automatically create a ubuntu and postgreSQL user named postgres. First, let’s change the password of postgres.

1
2
sudo su
passwd postgres

Then let’s login postgreSQL as user postgres.

1
2
sudo su postgres
psql

Then postgres=# would appear in the very front. Then let’s create a user we would use in our daily work. The same as your ubuntu user account is quite good. Creating as SUPERUSER is necessary for configuring python fucntions in postgreSQL by pl/python.

1
2
3
4
create user katherine superuser password 'houzi0105';
create database bigdata;
alter database bigdata owner to katherine;
\q

Next time, you can use the sentence below to login.

1
psql -U [dbuser] -d [db] -h 127.0.0.1 -p 5432

The abbreviated sentence can be:

1
psql bigdata

The initial settings have been done.

plpython3u

1
sudo gedit /etc/postgresql/9.5/main/environment
1
PYTHONPATH='/home/katherine/Documents/Coding/jfds/src:/home/katherine/venv/py35/lib/python3.5/site-packages'
1
sudo apt-get install postgresql-plpython3

Login postgresql and run:

1
CREATE EXTENSION plpython3u;

Reference: How to install 3rd party module for postgres pl/python PostgreSql 下安装 plpython

Install psycopg2 and sqlalchemy

Install the Dependencies

1
sudo apt-get install python-psycopg2

Then run this command in your virtualenv

1
2
pip install psycopg2
pip install sqlalchemy==1.1.1

Reference: pip 安装特定版本的 Python 包

Sougou Input

Installation

若是ubuntu14或以上系统,只要双击下载的.deb文件,点击install,之后在System Settings - Language Support中选择fcitx,注销再登录,然后在键盘符号处点击设置 - +添加sougoupinyin输入法即可。

若还无法正常使用

我的ubuntu14安装了搜狗输入法并设置后,仍然无法正常使用,参考,不过须把im-switch换成im-config才行。具体步骤如下:

第一,添加源:

1
sudo add-apt-repository ppa:fcitx-team/nightly

第二,更新系统

1
sudo apt-get update

第三,安装fcitx:

1
sudo apt-get install fcitx

第四,安装fcitx的配置工具:

1
sudo apt-get install fcitx-config-gtk

第五,安装fcitx的table-all软件包:

1
sudo apt-get install fcitx-table-all

第六,安装im-config: 因为我按照他原来的步骤操作时,最后一步提示我im-switch与安装冲突,要安装im-config,呵呵。

1
sudo apt-get install im-config

第七,用dpkg命令安装搜狗输入法资源包

1
sudo dpkg -i [资源包文件名.deb]

第八,设置语言选项 System Settings - Language Support - fcitx 第九,注销 第十,在fcitx配置中添加sougou pinyin。

Small problems

Ubuntu-16-04-Pycharm无法切换搜狗输入法

In Ubuntu 16.04, Sougou Input Method cannot be used in Cmaptools and Pycharm. The solution is add the following 3 lines to the top of the start file such as /usr/dev/pycharm-2016.2/bin/pycharm.sh.

1
2
3
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx

Then we can type in Chinese character by Sougou Input Method in Pycharm. Solution for Cmaptools is similar. The only problem left is the small menu of alternative characters does not follow tightly behind the input curser any more.

Install CmapTools

Reference: How to install a .bin file

1
2
chmod a+x name_of_file.bin
sudo ./name_of_file.bin

In order to get full access to Cmaps directory, I need to choose “where to install” as /home/katherine/IHMC CmapTools rather than /root/IHMC CmapTools. Then you can have the My_Cmaps file under directory /home/katherine.

Every time use bash CmapTools in the directory of file CmapTools to start it.

Install Pycharm

Reference: Install a .tar.gz file

1
2
tar -zxvf /home/katherine/Documents/Software/pycharm-professional-2016.2.3.tar.gz -C /home/katherine/
cd /home/katherine/pycharm-2016.2.3/

Then:

1
bash pycharm.sh

And the Installation process would start. This is also the way to start Pycharm after installation.

Install Git

1
2
sudo apt-get install git
sudo apt-get install git-core

Get Access to Google by Firefox

Install shadowsocks GUI

If you use Ubuntu like me, you can follow the code below.

1
2
3
sudo add-apt-repository ppa:hzwhuang/ss-qt5
sudo apt-get update
sudo apt-get install shadowsocks-qt5

For other OS please see here. You need to buy the service yourself, or you need a good boss like I have =.=

Then search “shadowsocks” in your computer and start the application. Configure the server and connect.

Install the Add-on foxyproxy for Firefox

Follow the steps in http://sslite.top/136/. Make sure the shadowsocks is working when foxyproxy starts to work.

Other References

How do I open, create, edit, and view a file in Linux?

Almost all the problems and issues I met with are listed here. If you have other questions as well as answers, it’s very appreciated to tell me.

坚持原创技术分享,您的支持将鼓励我继续创作!