因为开发了多个Django项目,有CMS,ERP,SCADA。分别用的不同版本,搞的virtualenv有些混乱,所以重新安装,用virtualenvwapper隔离开。
WIN7下下载安装virtualbox,4.3.8,安装很简单。
新建centos6.4,分配2G 内存,安装也很顺利。最后一步崩溃收集那步老失败,CTL+ALT+BACKSPACE直接进入系统,然后System-administration-kernel crash dump禁用就好了。
配置好简单应用,如文件夹打开方式,网络配置等
参考另外一篇关于中文输入法安装的,用的ibus拼音输入法。
下载pycharm3,安装时需要jdk支持。yum安装的只是openjdk不能用,据说时oracle授权的问题,新的linux都没有jdk了。
Ubuntu:
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java7-installer
centos:
从官网下载rpm,rpm -ivh安装,默认到/usr/java.
配置下环境变量:
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 =====
因为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: 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下
从这里http://www.pip-installer.org/en/latest/installing.html get-pip.py,
sudo python2.7 get-pip.py
sudo pip install 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
使用时
source ~/.bashrc
如果要删除一个virtualenv需要先deactivate,如下:
deactivate rmvirtualenv cms
因为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
配置用户名跟email,以后提交git时用
$ git config --global user.name quanpower $ git config --global user.email [email protected] $ git config --list
返回:
user.name=quanpower
[email protected]
yum list installed | grep -i mysql
yum remove mysql mysql-*
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
yum --enablerepo=remi,remi-test install mysql mysql-server
yum list installed | grep -i mysql
/etc/init.d/mysqld start## use restart after update
service mysqld start## use restart after update
chkconfig --levels 235 mysqld on
mysql_upgrade -u root -p
Now my MySql version is 5.5.32
mysqldb在pip中叫MySQL-python,
pip install MySQL-python
上面因为没安装mysql-devel会报错,
yum --enablerepo=remi install mysql-develInstalling : mysql-devel-5.5.36-1.el6.remi.i686
因为想添加个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.rpm2.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 oncentos需要手动初始化下然后设置默认自启动。
连接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
安装完成之后, 系统中会多出一个名为 postgres 的用户, 这个用户用于登录数据库. 但无法直接用该用户在 shell 或 xdm 中登录, 须先用其它用户登录 shell, 然后su到该用户. 先为该用户设置一下密码
这样会以 postgres 用户身份登录, 如果要输入密码就输入刚才为 postgres 用户设置的密码.
PostgreSQL默认的超级管理员密码是postgres
连接方法:psql -U postgres(注意,是大写的-U)
默认密码为空
修改密码的方法是,用psql登入管理:psql -U postgres
然后用这样的命令来修改密码:alter user postgres with password 'new password
如果上面每个句子输入之后没回显结果, 并且交互环境开头变为了postgres-#(注意 # 前是一个减号而非等号), 请查看一下句尾的分号是否漏掉了.
root@server2-virtual-machine:~# vi /etc/postgresql/9.1/main/postgresql.conf
在SCADA系统中需要科学计算以及读取底层硬件采集的数据,需要按照MODBUS协议解析。所以用到以下包:
pip install pymodbus
pip install numpy
比较折腾的时这个,因为比较大,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
pip install Django