Python upgraded smoothly from 2.4 to 2.7

Source: Internet
Author: User
Tags install django pip install django

Python upgraded smoothly from 2.4 to 2.7

Python 2.6.6 is installed on the server by default. This version is a little troublesome, that is, it does not support django1.7. If Django is installed by default in 2.6.6, version 1.7 is installed, and the following error is displayed at startup:

>>> Import django
Traceback (most recent call last ):
File "", line 1, in
File "/usr/lib/python2.6/site-packages/django/_ init _. py", line 1, in
From django. utils. version import get_version
File "/usr/lib/python2.6/site-packages/django/utils/version. py", line 7, in
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

Therefore, you need to upgrade the original python2.6 in the machine to 2.7. However, note that the default yum path in linux uses the original python. If you do not pay attention to this, python is 2.7, but yum reports an error. This is a tragedy.

So we will follow the steps step by step:
1) To download python 2.7.8, many people will say that python3 is the future trend. Why not directly go to python3, because the majority of servers are installed on 2.x. if python 3 is used, it is a little big, will be pulled.
# Wget http://python.org/ftp/python/2.7.8/Python-2.7.8.tgz
2) Compile and install
# Tar-zxvf Python-2.7.8.tar.bz2
#./Configure -- prefix =/usr/local/python27
# Make & make install
3) Rename python 2.6. This step is for yum
# Mv/usr/bin/python/usr/bin/python_old
4) add python 2.7 to the "shortcut" of linux"
# Ln-s/usr/local/python27/bin/python/usr/bin/
5) Check python at this time.
1234 Python 2.7.8 (default, Jul 16 2016, 10:38:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

6) change the original yum configuration file.

# Vim/usr/bin/yum
Then, set the first line #! /Usr/bin/python #! /Usr/bin/python2.6, save and exit.
7) Check yum at this time to see if it is normal.

Django Installation Process
I personally recommend installing Django using pip, which is simple and easy to understand.

# Yum install python-pip
# Pip install -- upgrade pip (this is the command to upgrade pip)
# Pip install Django

After installation, start python and check whether the installation is successful.
[Root @ chen-cs-001 pip-1.2.1] # python
Python 2.7.8 (default, Jul 16 2016, 10:38:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> Import django
>>> Django. VERSION
(1, 9, 7, 'final', 0)
>>> Django. get_version ()
'1. 100'
>>> Print (django. _ path __)
['/Usr/local/python27/lib/python2.7/site-packages/django']

Installation successful ~ OK! The path is shown above ~

Problem Solving
Q: When importing django, the following prompt is displayed: importError: No module named utils. version.
A: You can uninstall and reinstall pip uninstall Django. Then, pip install Django pay attention to "D" in uppercase. You can also try pip uninstall django in earlier versions with the name django.

Q: The system comes with python2.7, which is replaced by python3 by default. After django is installed, it cannot be imported in python3. It can be imported in 2.7. How can this problem be solved?
A:
# Apt-get install python3-pip # (note is python3 !)
Then

# Pip3 install Django -- user

Q:
SyntaxError: invalid syntax
>>> Django-admin startproject mysite
File "", line 1
Django-admin startproject mysite

A: You need to add the Scripts in the Python directory to the environment variable directory.

Q: pip install Django prompt ImportError: No module named pip
A:
# Wget https://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz
# Tar xzf pip-1.2.1.tar.gz
# Cd pip-1.2.1/
# Python setup. py install

Q: ImportError: No module named pkg_resources
A:
Wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
Tar zxvf setuptools-0.6c11.tar.gz
Cd setuptools-0.6c11
Python setup. py build
Python setup. py install

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.