python3.6安裝Scrapy


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

1、安裝pyhthon

這個就不多說了,對應版本就下載對應的依賴包

2、安裝pywin32

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

下載對應版本的pywin32,直接雙擊安裝即可,安裝完畢之后驗證:

(注意:pywin32版本跟隨Python版本,即如果win是64位,但python是32位,pywin32要裝32位的)

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

# -*- 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位的竟然成功了(明顯是不能用,蛋碎一地-,-)。

后來發現問題,64位的提示的是‘Python 3.6-32’,有沒有發現什么? ‘36-32’!!!so,我把注冊表里python下面的3.6直接改名成3.6-32,安裝成功...

3、安裝pip

常識,不多說了,上篇有提到

4、安裝pyOPENSSL

在Windows下,是沒有預裝pyOPENSSL的

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

(可以直接pip安裝,但版本不一定新,如果不行再上官網)

5、安裝lxml

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

直接pip安裝

pip install lxml

6、安裝Twisted

這個其實在安裝Scrapy的時候會自動安裝,但是他需要visual C++ Build Tools 2015,無奈網速不給力實在下不下來,所以自己安裝了

網址:http://www.lfd.uci.edu/~gohlke/pythonlibs/,這里是已經編譯好的,可以直接pip安裝(需要wheel)

7、安裝Scrapy

終於在最后一步,折騰了一晚上....

pip install Scrapy

so easy 是不是=.=

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

 

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

 

打完收功==!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM