python3.6安裝Scrapy

環境:win10(64位), Python3.6(64位)python

一、安裝pyhthonwindows

這個就很少說了,對應版本就下載對應的依賴包ide

二、安裝pywin32ui

在windows下,必須安裝pywin32,安裝地址:http://sourceforge.net/projects/pywin32/spa

下載對應版本的pywin32,直接雙擊安裝便可,安裝完畢以後驗證:.net

(注意:pywin32版本跟隨Python版本,即若是win是64位,但python是32位,pywin32要裝32位的)命令行

安裝pywin32須要把Python的路徑寫入註冊表中,運行下面腳本:code

# -*- coding: utf-8 -*-
# Run from the command window (Run as Administrator!):
# python registerPython.py

# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Löw for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm

import sys

from _winreg import *

# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
installpath = "D:\Program Files\Python36"  # 注意這裏是python安裝路徑

regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
    installpath, installpath, installpath
)

def RegisterPy():
    try:
        reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
    except EnvironmentError:
        try:
            print("No Key Found, attempting to register")
            reg = CreateKey(HKEY_LOCAL_MACHINE, regpath)
            SetValue(reg, installkey, REG_SZ, installpath)
            SetValue(reg, pythonkey, REG_SZ, pythonpath)
            CloseKey(reg)
        except:
            print("*** Unable to register!")
            return
        print("--- Python", version, "is now registered!")
        return
    if (QueryValue(reg, installkey) == installpath and
        QueryValue(reg, pythonkey) == pythonpath):
        CloseKey(reg)
        print("=== Python", version, "is already registered!")
        return
    CloseKey(reg)
    print("*** Unable to register!")
    print("*** You probably have another Python installation!")

if __name__ == "__main__":
    RegisterPy()
pythonregistry.py

我在裝pywin32的時候出現個很蛋疼的狀況,我先下載了64位的,安裝提示'python 3.6-32'註冊表未找到,試了下裝32位的居然成功了(明顯是不能用,蛋碎一地-,-)。xml

後來發現問題,64位的提示的是‘Python 3.6-32’,有沒有發現什麼? ‘36-32’!!!so,我把註冊表裏python下面的3.6直接更名成3.6-32,安裝成功...htm

三、安裝pip

常識,很少說了,上篇有提到

四、安裝pyOPENSSL

在Windows下,是沒有預裝pyOPENSSL的

安裝地址:https://launchpad.net/pyopenssl

(能夠直接pip安裝,但版本不必定新,若是不行再上官網)

五、安裝lxml

解析XML的庫,很強大,作爬蟲BS4,selenium,XPATH都會用到

直接pip安裝

pip install lxml

六、安裝Twisted

這個其實在安裝Scrapy的時候會自動安裝,可是他須要visual C++ Build Tools 2015,無奈網速不給力實在下不下來,因此本身安裝了

網址:http://www.lfd.uci.edu/~gohlke/pythonlibs/,這裏是已經編譯好的,能夠直接pip安裝(須要wheel)

七、安裝Scrapy

終於在最後一步,折騰了一夜....

pip install Scrapy

so easy 是否是=.=

pip 會另外下載其餘依賴的包,這些就不要咱們手動安裝啦,等待一會,大功告成!

 

最後驗證一下,命令行下輸入:Scrapy

 

打完收功==!

相關文章
相關標籤/搜索