一、标题:django初始化安装异常错误问题总结
二、目录
2.1 pip 安装
2.2 加载django SyntaxError: invalid syntax异常错误
2.3 运行yum报错:No module named yum处理
2.4 vimrc E488: Trailing characters: silent put! =infor错误
三、环境说明
3.1 Oracle VM VirtualBox Centos 6.6 精简版 端口转发 Nat上网
[root@Hero ~]# python Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
django 最开始由于是用 pip安装 最新1.8.2版本的,It works with Python 2.7,3.2, 3.3, or 3.4 而系统自带python版本是2.6.6
故需要升级为python2.7版本 或者 安装低版本的django。
四、安装记录
4.1 pip 安装 (最精简可行方法,其他方法都容易少安装包)
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python get-pip.py
pip install django
Ubuntu12.04LTS Django卸载
1. 安装pip
sudo apt-get install python-pip
2. 卸载Django
sudo pip uninstall Django
3. sudo apt-get autoremove
4.2 加载import django SyntaxError: invalid syntax异常错误、或 django-admin.py startproject 时报错
报错记录:
[root@Hero ~]# python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "/usr/lib/python2.6/site-packages/django/utils/version.py", line 7, in <module>
from django.utils.lru_cache import lru_cache
File "/usr/lib/python2.6/site-packages/django/utils/lru_cache.py", line 28
fasttypes = {int, str, frozenset, type(None)},
^
SyntaxError: invalid syntax
报错关键字: File "/usr/lib/python2.6/site-packages/django/utils/lru_cache.py", line 28 fasttypes = {int, str, frozenset, type(None)}, ^ SyntaxError: invalid syntax
解决错误的探索:
各种Google,没找到有帖子记录过,即使有是没有最终解决的,之前以为是因为和我装了Xadmin影响,也删了,最后才发现其实是不冲突的。
1.升级python 因为系统现有的某些软件是依赖python2.6.6的,所以不能卸载现有版本之后重新安装python2.7,否则直接升级到python2.7之后可能会导致yum等不能使用。
2.下载低的django版本
卸载Django
sudo pip uninstall Django
如何升级这篇文章讲的最详细:
推荐:推荐
完全重装python和django、以及yum ,可解决上述报错 ,见下文:
4.3 运行yum报错:No module named yum处理 (
当前系统存在多个python、或python资源丢失)
python:
/usr/bin/python2
.6
/usr/bin/python
/usr/bin/python2 .6-config /usr/lib/python2 .6 /usr/lib64/python2 .6 /usr/include/python2 .6 /usr/share/man/man1/python .1.gz
报错记录:
报错情况:
- There was a problem importing one of the Python modules
- required to run yum. The error leading to this problem was:
-
- No module named yum
-
- Please install a package which provides this module, or
- verify that the module is installed correctly.
-
- It's possible that the above module doesn't match the
- current version of Python, which is:
- 2.6.6 (default, Nov 8 2014, 23:03:00)
- [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)]
-
- If you cannot solve this problem yourself, please go to
- the yum faq at:
- http://wiki.linux.duke.edu/YumFaq
试行方法:检验Python 版本,将yum 指定python版本
#python -V
得到版本路径,下面修改用 #vi /usr/bin/yum 将 #!/usr/bin/python 修改为 #!/usr/bin/python2.6
第一种方法还不行则,使用下面方法重装。
最终方法:完全重装python和yum
1、删除现有Python
[root@hero ~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联 [root@hero ~]# whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
[root@hero ~]# whereis python ##验证删除,返回无结果 2、删除现有的yum
[root@hero ~]# rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps
[root@hero ~]# whereis yum |xargs rm -frv
3、从http://mirrors.ustc.edu.cn/centos/6.6/os/x86_64/Packages/下载相应的包
python-2.6.6-36.el6.x86_64.rpm
python-devel-2.6.6-36.el6.x86_64.rpm
python-libs-2.6.6-36.el6.x86_64.rpm
python-pycurl-7.19.0-8.el6.x86_64.rpm
python-setuptools-0.6.10-3.el6.noarch.rpm
python-urlgrabber-3.9.1-8.el6.noarch.rpm
python-iniparse-0.3.1-2.1.el6.noarch.rpm
rpm-python-4.8.0-32.el6.x86_64.rpm
yum-3.2.29-40.el6.centos.noarch.rpm
yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
yum-utils-1.1.30-14.el6.noarch.rpm
yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm
yum-plugin-protectbase-1.1.30-14.el6.noarch.rpm
yum-plugin-aliases-1.1.30-14.el6.noarch.rpm
yum-plugin-downloadonly-1.1.30-14.el6.noarch.rpm
15 个 rpm
由于源中版本会更新,具体请查看URL中的版本再下载下来!
[root@hero ~]# rpm -Uvh --replacepkgs python*.rpm
[root@hero ~]# rpm -Uvh --replacepkgs rpm-python*.rpm yum*.rpm 可能之间还需要zlib和zlib-devel包,根据情况下载并安装!
4.4 vimrc E488: Trailing characters: silent put! =infor错误
1.没安装vim 安装vim 三个包,安装后 souce .virmrc
五、结果:
5.1 预备配置
virtual Box 8080 端口 加入 端口转发
8080端口防火墙开启
保存
重启 #service iptables restart
[root@Hero python_yum_apk]# python Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import yum >>> exit() 无No module named yum报错 [root@Hero python_yum_apk]#
5.2 django 初始化 测试:
#django-admin.py |tail -15
#django-admin.py startproject firstweb
#python manage.py runserver 0.0.0.0:8080
Validating models...
0 errors found
May 21, 2015 - 05:00:12
Django version 1.5.8, using settings 'firstweb.settings'
Development server is running at http://0.0.0.0:8080/
Quit the server with CONTROL-C.
[21/May/2015 05:00:15] "GET / HTTP/1.1" 200 1959
|