从新安装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
相关文章
相关标签/搜索