Installation of python common libraries under windows

Reference link: How to print without line breaks in Python?

The installation of python common libraries under windows requires that the python development environment of annaconda is installed. As long as anaconda has been installed, installing other libraries is easy. Just use pip. If python is installed normally, it will bring its own pip installation tool, which can be viewed in the python scripts installation directory. Specific installation steps: Use Anaconda to manage the python development environment under windows The installation of python common libraries is the cornerstone of python crawler development.

  1. Installation of urllib and re library

These two libraries are the libraries that come with python. As long as python is installed correctly, you can directly call the two libraries. The verification in python mode is as follows

import urllib

import urllib.request

urllib.request.urlopen('http://www.baidu.com')

< http.client.HTTPResponse object at 0x0000024222C09240>

import re

  1. Installation of requests request library

Execute the command under pip3 install requests dos to install

Test whether the request library is installed correctly under python interaction

import requests

requests.get('http://www.baidu.com')

< Response [200]>

  1. Installation of selenium library

Mainly used to drive the browser, do tests and the like, js rendering and debugging

pip3 install selenium executes the installation, if you delete the library, directly pip3 uninstall selenium

Test whether it is installed correctly

import selenium

from selenium import webdriver

driver = webdriver.Chrome()

At this time, the system will start a blank browser, if it fails, you need to install the chromdriver driver, decompress it and place it in the directory after the python configuration environment variable.

DevTools listening on ws://127.0.0.1:12052/devtools/browser/1f2faef9-0748-40f0-b955-9e41362ce55e

driver = webdriver.Chrome()

DevTools listening on ws://127.0.0.1:12722/devtools/browser/5ba65a50-df4a-47fd-b2d6-d313578d539d

driver.get('http://www.baidu.com') #The browser opened at this time will jump to the Baidu homepage.

driver.page_source #Can directly print the code of the current Baidu webpage

  1. Installation of phantomjs library

No interface browser, browser driver implementation under command line, complementary to selenium, the former will open the browser

  1. Download the phantomjs installation package on the phantomjs official website, http://phantomjs.org/download.html

  2. After placing it in the specified installation directory, configure environment variables, bin directory

  3. Execute phantomjs directly under dos to see if the configuration is successful, as follows:

C:\Users\Robot_CHEN>phantomjs

phantomjs>

  1. Installation and functional test

import selenium

from selenium import webdriver

driver = webdriver.PhantomJS() #Pay attention to the difference between webdrive.Chrom() in selenium

driver.get('http://www.baidu.com')

driver.page_source

  1. Installation of lxml library

xpath web page parsing library, realize web page parsing. pip3 install lxml can be installed directly

Under python interaction, use import lxml to confirm whether the installation is successful

  1. The installation of beatifulsoup web page parsing library depends on lxml library

Installation: pip3 install beatifulsoup4

Test installation:

from bs4 import BeautifulSoup #Use beautifulsoup to import from bs4 module

soup = BeautifulSoup('','lxml')

  1. Installation of pyquery web page parsing library

pip3 install pyquery performs the installation.

from pyquery import PyQuery as pq

doc = pq('')

doc = pq('Hello World')

result = doc('html').text()

result

' Hello World'

  1. Installation of pymysql repository

The driver library installation command for operating the mysql database: pip3 install pymysql. After the installation is complete, use the code python to operate the mysql database and execute CRUD.

import pymysql #import pymysql

Open database connection

db= pymysql.connect(host="localhost",user="root",

password="123456",db="mydatabase",port=3306)

Use cursor() method to get operation cursor

cur = db.cursor()

#1. Query operation

Write sql query statement user corresponding to my table name

sql = "select * from emp3"

try:

cur.execute(sql) #Execute sql statement

results = cur.fetchall() #Get all records of the query

print("id","name","password")

#Traversal results

for row in results :

id = row[0]

name = row[1]

password = row[2]

print(id,name,password)

except Exception as e:

raise e

finally:

db.close()

  1. Installation of pymongo, operation of mongodb data

The installation is still pip install pymongo

import pymongo

client = pymongo.MongoClient('localhost')

db = client['mymongodb']

coll = db['mycoll']

mydict = { "name": "RUNOOB", "alexa": "10000" }

coll.insert_one(mydict)

print(coll)

''' The test results are as follows:

Collection(Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'mymongodb'), 'mycoll')

'''

  1. installation of redis

pip install redis can be installed

import redis

result = redis.Redis('localhost',6379)

result.set('name','jack')

print(result.get('name')) #b'jack'

  1. The installation of flask, mainly used when setting up the web

You can view it in Flask's official website documentation, http://docs.jinkan.org/docs/flask/

Installation method pip install flask, test import flask in python interactive mode to see if an error is reported

12 Django installation, web server framework

The installation is very simple pip install django, test import import django

  1. jupyter installation, powerful notepad

You can install jupyter with pip install jupyter. If you are using anaconda, jupyter is already installed by default. It is mainly used for online code writing and documentation, which is very powerful and convenient.

Unified statement: Regarding the original blog content, some of the content may be referenced from the Internet. If there is an original link, it will be quoted; if the original link is not found, please contact and delete it if there is any infringement. Regarding reposting the blog, if there is an original link, it will be declared; if the original link is not found, please contact to delete it if there is any infringement.

Recommended Posts

Installation of python common libraries under windows
09. Common modules of Python3
Installation and use of GDAL in Python under Ubuntu
Python version of OpenCV installation
Collection of Python Common Modules
Installation under centos6.9 of jenkins learning
Installation of deb package under Ubuntu
Several common modes of Python functions
A summary of 200 Python standard libraries!
Redis installation under ubuntu and windows
Installation of Docker CE under Ubuntu
How to verify successful installation of python
Installation and use of Mysql under CentOS
Which version of python does windows support
Installation and configuration of redis under centos7
Installation and uninstallation of CUDA under Ubuntu 16.04
Summary of common operations of Python time module
Analysis of common methods of Python multi-process programming
Python2.7 [Installation Tutorial]
7 features of Python3.9
Installation of pulseaudio and API usage under Ubuntu 12.04
Python - centos6 installation
Python Anaconda installation
Analysis of common methods of Python operation Jira library
Installation and configuration of rsync server under CentOS 6.5
Non-Root installation of Microsoft R Open under Centos
From installation to entry of FastDFS under Centos7
Installation and cracking of confluence6.3 operation records under Centos
Installation and cracking of Jira7 operation records under Centos
Detailed explanation of common tools for Python process control
Installation and usage instructions of rz/sz command under ubuntu
Install python3.6 under Ubuntu 16.04
Python MySQLd under Ubuntu
Centos source installation Python3
[python] python2 and python3 under ubuntu
LNMP installation under Ubuntu
Basics of Python syntax
Graphical installation of CentOS8
Basic syntax of Python
Basic knowledge of Python (1)
Redis3 installation under Centos7
Prettytable module of python
Detailed explanation of Spark installation and configuration tutorial under centOS7
A large inventory of commonly used third-party libraries in Python