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.
Then restart nautilus to make it work immediately.
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
SQLite libs need to be installed in order for Python to have SQLite support.
Use apt-get install
添加 PPA:
安装 Python 3.5:
安装新版pip:
Reference: 在 Ubuntu 14.04.3 上安装 Python 3.5
Build virtual env of Python
|
|
Then
Add the following code at the bottom of .bashrc
file.
Return to the terminal window.
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
|
|
pip-Uninstall Packages with Dependencies
install pip-autoremove
|
|
remove “somepackage” plus its dependencies:
|
|
Reference: pip-uninstall packages with dependencies
Install cx_oracle
Install Dependencies
Activate your virtual environment, and then do the following steps.
建议安装对应版本的python-dev
如python3.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
|
|
Set ORACLE_HOME location
|
|
然后添加以下语句到~/.bashrc
,然后保存。这是告诉安装程序oracle安装文件的位置,若后面出现cannot locate oracle installation
的提示,一定是这里没有设置好。注意:ORACLE_HOME 要指向绝对路径。
记得更新配置:
对以下文件建立软链接。
Install cx_oracle
|
|
Reference:
- cx_Oracle在virtualenv(python)中的pip安装
- cx_Oracle instant client install python3
- 在PostgreSQL中使用oracle_fdw访问Orcale(foreigh table)
Install
Install postgresql
Install postgresql
Add PostgreSQL Apt Repository
|
|
Install PostgreSQL
|
|
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:
Initial settings
postgreSQL
automatically create a ubuntu
and postgreSQL
user named postgres
.
First, let’s change the password of postgres
.
Then let’s login postgreSQL as user postgres
.
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
.
Next time, you can use the sentence below to login.
The abbreviated sentence can be:
The initial settings have been done.
plpython3u
|
|
|
|
|
|
Login postgresql and run:
Reference: How to install 3rd party module for postgres pl/python PostgreSql 下安装 plpython
Install psycopg2 and sqlalchemy
Install the Dependencies
|
|
Then run this command in your virtualenv
|
|
Reference: pip 安装特定版本的 Python 包
Sougou Input
Installation
若是ubuntu14或以上系统,只要双击下载的.deb
文件,点击install
,之后在System Settings
- Language Support
中选择fcitx
,注销再登录,然后在键盘符号处点击设置
- +
添加sougoupinyin输入法即可。
若还无法正常使用
我的ubuntu14安装了搜狗输入法并设置后,仍然无法正常使用,参考,不过须把im-switch
换成im-config
才行。具体步骤如下:
第一,添加源:
第二,更新系统
第三,安装fcitx:
第四,安装fcitx的配置工具:
第五,安装fcitx的table-all软件包:
第六,安装im-config:
因为我按照他原来的步骤操作时,最后一步提示我im-switch
与安装冲突,要安装im-config
,呵呵。
第七,用dpkg命令安装搜狗输入法资源包
第八,设置语言选项
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
.
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
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
Then:
And the Installation process would start. This is also the way to start Pycharm after installation.
Install Git
|
|
Get Access to Google by Firefox
Install shadowsocks
GUI
If you use Ubuntu like me, you can follow the code below.
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.