"Python" Ubuntu installs Django, mysqldb connection database "Xmapp"

Source: Internet
Author: User
Tags install django

My Ubuntu is installed by default python2.7 and 3.4, where Django is installed by Pip (tool for installing and managing Python packages)

Do not install PIP first install PIP tool

Apt-get Install Python-pip  
Apt-get Install Python3-pip
The first is the Python 2.x version of the installation tool  if you want Django on Python3, use the following.

Pip installs Django online after installation

  Pip  Install django==1.8        

After the equals sign is followed by the Django version number here my is 1.8, Pip applies to Python2, if you want to install under Python3, use the following method

  PIP3 Install django==1.8

Python3 installation just change Pip to PIP3

Test Django, and the output version number indicates that the installation was successful.

Then install the Mysqlclient,python connection database.

Install mysqlclient

After installation, the Python directory is dist-packages to be seen.

Open the Python console and enter import MySQLdb, which means the installation was successful without error.

Next, test the connection database:

>>>  Import Mysqldb>>> conn = mysqldb.connect (host= ' localhost ', user= ', passwd= ')

Press ENTER to find an error ...

Unable to connect to the database, because I am using the Xmapp environment, MySQL is not in the default path, the connection needs to specify the location of the Mysql.sock connect function parameters unix_socket= ' your Mysql.sock path '

Similarly, under the Django Project, setting.py configures the path of the Mysql.sock

Of course, if you are apt-get install the path by default when the line.

"Summed up a few questions about database Connectivity"

1. First check whether the database service is running

2. There may be a login IP limit, edit MySQL my.cnf

[Mysqld]

Bind-address =127.0.0.1 changed into 0.0.0.0

"Python" Ubuntu installs Django, mysqldb connection database "Xmapp"

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.