<commit_before>---
layout:     post
title:      "Python相关的安装笔记"
subtitle:   ""
date:       2016-04-22 12:00:00
author:     "Hooting"
header-img: "img/post-bg-2015.jpg"
tags:
    - python
    - install
---

## windows下安装pip

 - 在[pip网站](https://pip.pypa.io/en/latest/installing/)下载文件[get-pip.py](https://bootstrap.pypa.io/get-pip.py)。
 - 执行命令：
 > python get-pip.py 

## pip 的使用

 - 安装包：
 > pip install package-name
 - 升级包:
 > pip install package-name --upgrade
 - 删除包:
 > pip uninstall package-name

 ## 检查安装包的版本

 ### 通过pip命令

 > pip show YOUR_PACKAGE_NAME | grep Version
 
 ### 通过python代码

 > print pymysql.VERSION

## python 连接MySQL数据库

可用两个包，分别是[pymysql](https://github.com/PyMySQL/PyMySQL)或者MySQLdb连接数据库。

### pymysql安装

> pip install PyMySQL

### pymysql示例

```python
import pymysql

conn = pymysql.connect(host='127.0.0.1', port=3306,
                       user='root', passwd='<PASSWORD>',
                       db='test',use_unicode=1,charset="utf8")
try:
    with conn.cursor() as cursor:
        # Drop table if it already exist using execute() method.<commit_msg>update python-install file<commit_after>---
layout:     post
title:      "Python相关的安装笔记"
subtitle:   ""
date:       2016-04-22 12:00:00
author:     "Hooting"
header-img: "img/post-bg-2015.jpg"
tags:
    - python
    - install
---

## windows下安装pip

 - 在[pip网站](https://pip.pypa.io/en/latest/installing/)下载文件[get-pip.py](https://bootstrap.pypa.io/get-pip.py)。
 - 执行命令：
 > python get-pip.py 

## pip 的使用
- 安装包：
> pip install package-name
- 升级包:
> pip install package-name --upgrade
- 删除包:
> pip uninstall package-name

## 检查安装包的版本
### 通过pip命令
> pip show YOUR_PACKAGE_NAME | grep Version

### 通过python代码
> print pymysql.VERSION

## python 连接MySQL数据库
可用两个包，分别是[pymysql](https://github.com/PyMySQL/PyMySQL)或者MySQLdb连接数据库。

### pymysql安装
> pip install PyMySQL

### pymysql示例
```python
import pymysql

conn = pymysql.connect(host='127.0.0.1', port=3306,
                       user='root', passwd='<PASSWORD>',
                       db='test',use_unicode=1,charset="utf8")
try:
    with conn.cursor() as cursor:
        # Drop table if it already exist using execute() method.
{'fraction_non_alphanumeric': 0.1533084808946878, 'fraction_numerical': 0.027958993476234855, 'mean_word_length': 2.9685767097966727, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '663246', 'n_tokens_mistral': 950, 'n_tokens_neox': 936, 'n_words': 155}