從新安裝centos6.4,用virtualenvwapper配置開發環境

    由於開發了多個Django項目,有CMS,ERP,SCADA。分別用的不一樣版本,搞的virtualenv有些混亂,因此從新安裝,用virtualenvwapper隔離開。 html

1.virtualbox安裝

    WIN7下下載安裝virtualbox,4.3.8,安裝很簡單。 java

2.新建centos6.4

    新建centos6.4,分配2G 內存,安裝也很順利。最後一步崩潰收集那步老失敗,CTL+ALT+BACKSPACE直接進入系統,而後System-administration-kernel crash dump禁用就行了。 python

    配置好簡單應用,如文件夾打開方式,網絡配置等 mysql

3.安裝中文輸入法

    參考另一篇關於中文輸入法安裝的,用的ibus拼音輸入法。 linux

4.安裝pycharm

    下載pycharm3,安裝時須要jdk支持。yum安裝的只是openjdk不能用,聽說時oracle受權的問題,新的linux都沒有jdk了。 git

Ubuntu: web

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

centos: sql

從官網下載rpm,rpm -ivh安裝,默認到/usr/java. shell

配置下環境變量: 數據庫

sudo vim /etc/profile

添加以下:

export JAVA_HOME=/usr/java/jdk1.7.0_51
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
cd到pycharm目錄,
sh pycharm.sh開始安裝。安裝完成後註冊:
用戶名:yueting3527

註冊碼:
===== LICENSE BEGIN =====
93347-12042010
00001FMHemWIs"6wozMZnat3IgXKXJ
2!nV2I6kSO48hgGLa9JNgjQ5oKz1Us
FFR8k"nGzJHzjQT6IBG!1fbQZn9!Vi
===== LICENSE END =====

5.安裝python2.7.6

由於centos中默認python爲2.6,咱們但願用最新的2.7.6版本。可是必定要注意centos下好多都依賴2.6,譬如yum,咱們最好單獨安裝又不與2.6衝突。

依賴包

先安裝編譯所須要的依賴包

yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel

Python 2.7.6



# Python 2.7.6:
wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure --prefix=/usr/local 
make && make altinstall

    注意運用make altinstall而不是make install,這樣跟系統的2.6分別在不一樣的路徑下,也不會衝突了。python2.7在/usr/local/bin下,python2.6在/usr/bin下

6.安裝pip

    從這裏http://www.pip-installer.org/en/latest/installing.html get-pip.py,

sudo python2.7 get-pip.py

7.安裝及配置virtualenvwrapper

安裝virtualenvwrapper

sudo pip install virtualenvwrapper

配置virtualenvwrapper

    安裝好以後須要簡單配置下,主要是設置獨立環境的保存路徑:

$ export WORKON_HOME=~/Envs
$ mkdir -p $WORKON_HOME
$ source /usr/local/bin/virtualenvwrapper.sh
$ mkvirtualenv cms

    爲了以後使用方便不用每次都輸這麼長的指令,能夠加入~/.bashrc

export WORKON_HOME=~/Envs
export PROJECT_HOME=~/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

使用virtualenvwrapper

使用時

source ~/.bashrc

若是要刪除一個virtualenv須要先deactivate,以下:

deactivate
rmvirtualenv cms

8.安裝git

    由於yum的版本過低了,記得好像是1.7的,咱們用源碼編譯安裝。

先安裝一些依賴包,固然有些可能以及裝過了

sudo yum -y install curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel 

sudo yum autoconf
sudo wget https://git-core.googlecode.com/files/git-1.9.0.tar.gz
$ tar -zvxf git-1.9.0.tar.gz
$ cd git-1.9.0
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install

如今已經能夠用git命令了,用git把 Git 項目倉庫克隆到本地,以便往後隨時更新:

$ git clone git://git.kernel.org/pub/scm/git/git.git

9.git初始配置

配置用戶名跟email,之後提交git時用

$ git config --global user.name quanpower
$ git config --global user.email quanpower@gmail.com
$ git config --list

返回:

user.name=quanpower
user.email=quanpower@gmail.com

10.MySQL


升級mysql5.1->mysql5.5

To list Old MySql

yum list installed | grep -i mysql

To remove Old MySql

yum remove mysql mysql-*

Remi Dependency on CentOS 6 and Red Hat (RHEL) 6

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Install MySQL server

yum --enablerepo=remi,remi-test install mysql mysql-server

To list New MySql

yum list installed | grep -i mysql

start MySql server

/etc/init.d/mysqld start## use restart after update

OR

service mysqld start## use restart after update

chkconfig --levels 235 mysqld on

Last

mysql_upgrade -u root -p

Now my MySql version is 5.5.32

mysqldb

mysqldb在pip中叫MySQL-python,

pip install MySQL-python


上面由於沒安裝mysql-devel會報錯,

yum --enablerepo=remi install mysql-devel
Installing : mysql-devel-5.5.36-1.el6.remi.i686  



11.安裝PostgreSQL並配置

安裝PostgreSQL

    由於想添加個gis功能模塊,看django推薦gis用PostgreSQL數據庫,拿來試用下,安裝的時候有幾個注意的小問題。

1.To use the yum repository, you must first install the repository RPM. To do this, download the correct RPM from the repository RPM listing, and install it with commands like:

yum install http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm
2.Once this is done, you can proceed to install and update packages the same way as the ones included in the distribution.
yum install postgresql93-server postgresql93-contrib
service postgresql-9.3 initdb
chkconfig postgresql-9.3 on
centos須要手動初始化下而後設置默認自啓動。

安裝psycopg2

    鏈接PostgreSQL,選擇用的pyycopg2.另外用psycopg2時也碰到幾個問題

下載問題不大,直接去http://initd.org/psycopg/download/下載tar包就行了,或者在virtualenv裏使用

pip install psycopg2

均可。可是compile的時候報了幾回錯。

首先一個pg_cong問題,而後一個libpq問題。去看他文檔說了這麼幾點:

    Psycopg is a C wrapper to the libpq PostgreSQL client library. To install it from sources you will need:

  • A C compiler.

  • The Python header files. They are usually installed in a package such as python-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing.

  • The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them.

  • The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATHdirectory. Having it in the PATHgreatly streamlines the installation, so try runningpg_config --version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually/usr/lib/postgresql/X.Y/bin/) and add it to the PATH:

    $ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH

    You only need it to compile and installpsycopg2, not for its regular usage.

Note

The libpq header files used to compilepsycopg2should match the version of the library linked at runtime. If you get errors about missing or mismatching libraries when importingpsycopg2check (e.g. using ldd) if the modulepsycopg2/_psycopg.sois linked to the rightlibpq.so.

1.第一個用find / -name pg_config找到路徑,export到PATH裏。

export  PATH=/usr/pgsql-9.3/bin/:$PATH

2.第二個,折騰了很久,centos裏面python-dev 是python-devel,可是libpq-dev叫libpqxx-devel

sudo yum install python-devel libpqxx-devel

這樣就行了,yum install下,後面就一路順利了。

Dependencies Resolved

================================================================================
 Package                  Arch       Version                 Repository    Size
================================================================================
Installing:
 libpqxx                  i686       1:4.0.1-1.rhel6         pgdg93       189 k
 libpqxx-debuginfo        i686       1:4.0.1-1.rhel6         pgdg93       772 k
 libpqxx-devel            i686       1:4.0.1-1.rhel6         pgdg93        91 k
Installing for dependencies:
 postgresql93-devel       i686       9.3.3-1PGDG.rhel6       pgdg93       1.4 M

Transaction Summary
================================================================================
Install       4 Package(s)


另:若是是在ubuntu下sudo apt-get install python-psgcopg2

PostgreSQL使用

    安裝完成以後, 系統中會多出一個名爲 postgres 的用戶, 這個用戶用於登陸數據庫. 但沒法直接用該用戶在 shell 或 xdm 中登陸, 須先用其它用戶登陸 shell, 而後su到該用戶. 先爲該用戶設置一下密碼

passwd postgres
再切換到該用戶
me@host :~ su postgres
Password :
postgres@host : /home/ me $
若是當時處在某個用戶的 home 目錄, 如 /home/me 下, 則命令行會彈出一行錯誤信息
could not change directory to "/home/me"
由於 postgres 這個用戶沒法讀取當前用戶的 home 目錄. 以爲討厭的話能夠
cd /
此時在命令行輸入指令進入 Postgres 交互環境
psql
psql  ( version number )
Type   "help"   for  help .

postgres =#   input instructions here

這樣會以 postgres 用戶身份登陸, 若是要輸入密碼就輸入剛纔爲 postgres 用戶設置的密碼.

PostgreSQL默認的超級管理員密碼是postgres
鏈接方法:psql -U postgres(注意,是大寫的-U)
默認密碼爲空
修改密碼的方法是,用psql登入管理:psql -U postgres
而後用這樣的命令來修改密碼:alter user postgres with password 'new password


這時 postgres 用戶至關於數據庫的根用戶, 就像 root 用戶之於 Linux 系統同樣, 直接讓應用程序使用 postgres 用戶是比較危險的. 下面新建一個用戶
postgres =#   CREATE USER quanpower WITH PASSWORD 'XXXXXX';
CREATE ROLE
固然 Postgres 是不區分大小寫的. 不過這裏 (包括下文) 中將以全大寫標明這些是關鍵字, 而小寫的部分是可替換的. 密碼須要用引號包圍起來.

而後再創建一個新數據庫, 並受權quanpower 這個用戶可使用該數據庫
postgres =#   CREATE DATABASE SmartLinkCloud;
CREATE DATABASE
postgres =#   GRANT ALL PRIVILEGES ON DATABASE SmartLinkCloud TO quanpower;
GRANT
這樣就差很少好了. 下面開始搞 Python 與 SQLAlchemy 部分.

若是上面每一個句子輸入以後沒回顯結果, 而且交互環境開頭變爲了postgres-#(注意 # 前是一個減號而非等號), 請查看一下句尾的分號是否漏掉了.

root@server2-virtual-machine:~# vi /etc/postgresql/9.1/main/postgresql.conf
 

         1.監放任何地址訪,修改鏈接權限
          #listen_addresses = ‘localhost’改成 listen_addresses = ‘*’        
     2.啓用密碼驗證

          #password_encryption = on 改成 password_encryption = on
          3.可訪問的用戶ip段
          root@server2-virtual-machine:~# vi /etc/postgresql/9.1/main/pg_hba.conf ,並在文檔末尾加上如下內容
       
# to allow your client visiting postgresql server
          host all all 0.0.0.0 0.0.0.0 md5
         4.重啓
PostgreSQL數據庫
          root@server2-virtual-machine:~# /etc/init.d/postgresql restart

12.pymodbus&numpy & scipy

    在SCADA系統中須要科學計算以及讀取底層硬件採集的數據,須要按照MODBUS協議解析。因此用到如下包:

  • pymodbus
  • twisted
  • pyserial
  • zope.interface
  • scipy
  • numpy
其中pymodebus安裝後會自動把依賴的twisted,pyserial,zope.interface三個安裝上。

pymodbus

pip install pymodbus

numpy

pip install numpy

scipy

比較折騰的時這個,由於比較大,compile比較費時間,每次還不成功。


numpy.distutils.system_info.BlasNotFoundError: Blas (http://www.netlib.org/blas/) libraries not found. Directories to search for the libraries can be specified in the numpy/distutils/site.cfg file (section [blas]) or by setting the BLAS environment variable.
大stackoverflow.com救了我。 最後找到須要提早安裝下面的依賴包。
yum install lapack lapack-devel blas blas-devel
pip install scipy


13.Django


pip install Django
相關文章
相關標籤/搜索