CentOS中使用Python遇到的几个问题
用Python搞了一个从excel中读取cobbler节点信息并加入cobbler中的脚本,运行的过程中出了不少问题,这里记录下来,方便日后查找!
相关阅读:
一、CentOS中安装python,yum install python,我通过这个命令安装python,默认安装的是2.6的版本,但是当我把python 2.6安装完成后,发现cobbler的WEB管理页面无法打开了,查看apahce的错误日志:
[Sun Jul 07 20:13:01 2013] [error] [client 192.168.21.94] ImportError: cannot import name urandom
[Sun Jul 07 20:13:02 2013] [error] [client 192.168.21.94] File does not exist: /var/www/html/favicon.ico
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] mod_wsgi (pid=10816): Target WSGI script '/usr/share/cobbler/web/cobbler.w
sgi' cannot be loaded as Python module.
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] mod_wsgi (pid=10816): Exception occurred processing WSGI script '/usr/shar
e/cobbler/web/cobbler.wsgi'.
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] Traceback (most recent call last):
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] File "/usr/share/cobbler/web/cobbler.wsgi", line 9, in <module>
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] import django.core.handlers.wsgi
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", li
ne 10, in <module>
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] from django import http
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] File "/usr/lib/python2.6/site-packages/django/http/__init__.py", line 12
3, in <module>
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] from django.utils.http import cookie_date
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] File "/usr/lib/python2.6/site-packages/django/utils/http.py", line 7, in
<module>
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] from email.Utils import formatdate
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] File "/usr/lib64/python2.6/email/__init__.py", line 79, in __getattr__
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] __import__(self.__name__)
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] File "/usr/lib64/python2.6/email/utils.py", line 27, in <module>
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] import random
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] File "/usr/lib64/python2.6/random.py", line 47, in <module>
[Sun Jul 07 20:31:09 2013] [error] [client 192.168.21.94] from os import urandom as _urandom
缺少urandom模块,python2.6版本里默认没有这个模块,随即将python升级到2.7版本。
升级过程:
1、下载Python 2.7源码:
wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
下载
2、解压源码包:
tar -zxvf Python-2.7.2.tgz
3、编译:
cd Python-2.7.2
./configure --prefix=/usr
4、make&&make install
安装完成后测试web界面可以正常打开了,但是使用yum安装软件的时候会发现不能使用,原因是yum与python有依赖关系,yum是急于python写的,运行yum命令时会调用pyton;
vi /usr/bin/yum
将#!/usr/bin/pyton 改成:#!/usr/bin/pyton2.6,改成你系统默认的版本即可,不然他会调用高版本的python软件包,但是是找不到的,需要做相关配置才行,这里为了方便就直接改了就可以使用了。