python26pip
⑴ windows下如何安裝pip
方法如下:
1、pip是依賴python的,首先檢查下windows機器上有沒有安裝python,或者有沒有添加到環境變數中,如果都沒有需要安裝或者加入環境變數
(1)python26pip擴展閱讀:
pip 是一個現代的,通用的 Python 包管理工具。提供了對 Python 包的查找、下載、安裝、卸載的功能。
indows 10是Windows 8.1的下一代操作系統。Windows 8.1的發布並未能滿足用戶對於新一代主流Windows系統的期待。代號為「Windows Threshold」的Windows10於2014年10月2日發布技術預覽版。 於2015年7月29日發行正式版。
新特性
全設備平台制霸,Win10將實現大一統壯舉
從4英寸屏幕的「迷你」手機到80英寸的巨屏電腦,都將統一採用Windows 10這個名稱。這些設備將會擁有類似的功能,微軟正在從小功能到雲端整體構建這一統一平台,跨平台共享的通用技術也在開發中。
目前的Windows10預覽版主要為台式機和筆記本打造,Windows Insider Program也會登陸。與此同時,Windows 10手機版的名稱敲定:Windows10 Mobile,從此再無Windows Phone。
高效的多桌面、多任務、多窗口
分屏多窗口功能增強,現在你可以在屏幕中同時擺放四個窗口,Win10還會在單獨窗口內顯示正在運行的其他應用程序。同時,Win10還會智能給出分屏建議。
多桌面,現在你可以根據不同的目的和需要來創建多個虛擬桌面,切換也十分方便。點擊加號即可添加一個新的虛擬桌面。
資料鏈接:網路 PIP網路 windows
⑵ python 第三方庫怎麼安裝
【方法一】: 通過setuptools來安裝python模塊
首先下載
NOTE: 最好下載個setuptools,本人是15.2版本,裡麵包含了ez_setup
運行 python ez_setup.py
D:\work\installation\setuptools-15.2\setuptools-15.2>python ez_setup.py > 1.txt
Extracting in c:\users\admini~1\appdata\local\temp\tmpbxikxf
Now working in c:\users\admini~1\appdata\local\temp\tmpbxikxf\setuptools-15.2
Installing Setuptools
......
Copying setuptools-15.2-py2.7.egg to c:\python27\lib\site-packages
setuptools 15.2 is already the active version in easy-install.pth
Installing easy_install-script.py script to C:\Python27\Scripts
Installing easy_install.exe script to C:\Python27\Scripts
Installing easy_install-2.7-script.py script to C:\Python27\Scripts
Installing easy_install-2.7.exe script to C:\Python27\Scripts
Installed c:\python27\lib\site-packages\setuptools-15.2-py2.7.egg
Processing dependencies for setuptools==15.2
Finished processing dependencies for setuptools==15.2
運行 easy_install py
D:\work>easy_install py #py 為第三方庫文件
Searching for py
Best match: py 1.4.26
Adding py 1.4.26 to easy-install.pth file
Using c:\python27\lib\site-packages
Processing dependencies for py
Finished processing dependencies for py
【方法二】: 通過pip來安裝python模塊
安裝 easy_install pip
D:\work>easy_install pip
Searching for pip
Best match: pip 6.1.1
Processing pip-6.1.1-py2.7.egg
pip 6.1.1 is already the active version in easy-install.pth
Installing pip-script.py script to C:\Python27\Scripts
Installing pip.exe script to C:\Python27\Scripts
Installing pip2.7-script.py script to C:\Python27\Scripts
Installing pip2.7.exe script to C:\Python27\Scripts
Installing pip2-script.py script to C:\Python27\Scripts
Installing pip2.exe script to C:\Python27\Scripts
Using c:\python27\lib\site-packages\pip-6.1.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
運行 pip install xlrd
Usage:
pip <command> [options]
Commands:
install Install packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
search Search PyPI for packages.
wheel Build wheels from your requirements.
zip DEPRECATED. Zip indivial packages.
unzip DEPRECATED. Unzip indivial packages.
help Show help for commands.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring
environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be
used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output.
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form
[user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should
attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists:
(s)witch, (i)gnore, (w)ipe, (b)ackup.
--trusted-host <hostname> Mark this host as trusted, even though it does
not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file
containing the private key and the certificate
in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine
whether a new version of pip is available for
download. Implied with --no-index.
【方法三】:直接從網上下載下可執行文件來安裝.
比如說,去 >>> pythonlibs <<< 網站,提供了很多Python非官方包下載,二進制文件,下載安裝方便.
⑶ 如何在python控制台中使用pip安裝本地包
安裝Python包,的確是pip最為方便了,簡單快捷,因為它直接是從pypi上面下載文件,保證文件的安全性和可靠性,並且資源豐富;
下面是安裝步驟:
下載 setuptools,注意對應 Python 的版本,完成後運行 exe 即可完成安裝
setuptools-1.4.1.win32-py2.6.exe
下載 pip
pip-1.4.1.tar.gz
安裝 pip
5.1 解壓pip-1.4.1.tar.gz
5.2 運行CMD,進入命令行
5.3 用CD命令進入 pip 解壓目錄
5.4 輸入 "python setup.py install"
5.5 添加環境變數 path = C:\Python26\ArcGIS10.0\Scripts
驗證是否安裝成功,運行CMD,進入命令行,輸入pip;
如果出現pip的用法介紹,說明安裝成功。
進入命令行,輸入 "pip install package",package為安裝包名稱,就可以隨意使用了。
⑷ 如何在win7下安裝Python及配置
1、首先,從網路搜索python官網下載適合自己電腦python版本。
⑸ python在win10環境下怎樣安裝wxpython
Python 與 wxPython 運行環境安裝
分 別安裝python-2.6.2.msi、wxPython2.8-win32-unicode-2.8.10.1-py26.exe
wxPython2.8-win32-docs-demos-2.8.10.1.exe 和py2exe-0.6.9.win32-py2.6.exe
python安裝路徑採用默認C:/Python26,安裝完畢後,將這個目錄添 加到path環境變數中
Pydev開發環境安裝
如 果未安裝jre,請到www.java.com下 載安裝
解壓縮eclipse-SDK-3.3.2-win32.zip 至D:/eclipse-3.3.2
解壓縮 org.python.pydev.feature-1.4.7.2843.zip 至D:/eclipse-3.3.2/pydev-1.4.7/eclipse
在D:/eclipse-3.3.2/eclipse 下創建一個文件夾「links」並在文件夾下創建文件pydev-1.4.7.link
用記事本打開pydev-1.4.7.link ,輸入:path=D:/eclipse-3.3.2/pydev-1.4.7
解壓後的目錄結構如下:
目錄結構代碼
D:/
+eclipse-3.3.2
|--+eclipse
||--+configuration
||--+features
||--+links
||--+plugins
||--+readme
||---eclipse.exe
|
|--+pydev-1.4.7
|--+eclipse
|--+features
|--+plugins
importwx
if__name__=='__main__':
app=wx.PySimpleApp()
frame=wx.Frame(parent=None)
frame.Show(True)
app.MainLoop()
importwx
if__name__=='__main__':
app=wx.PySimpleApp()
frame=wx.Frame(parent=None)
frame.Show(True)
app.MainLoop()
fromdistutils.coreimportsetup
importpy2exe
setup(windows=[{"script":"app1.py"}])
fromdistutils.coreimportsetup
importpy2exe
setup(windows=[{"script":"app1.py"}])
運行並配置Pydev
雙 擊D:/eclipse-3.3.2/eclipse/eclipse.exe運行eclipse,選擇一個workspace,待載入完畢後,
打 開菜單:Window >> Preferences…,在彈出的對話框中,進入Pydev >> Interpreter – Python,
點擊Auto Config會自動載入Python 運行環境配置
開發wxPython應用
新 建一個Pydev Project:proj1,然後新建一個Pydev Mole:app1.py,輸入代碼:
Python代碼
[python]view plain
右擊app1.py,選擇debug as >> python run, 即可運行
把python腳本轉化成exe
新 建模塊:convert2exe.py,輸入代碼:
Python代碼
[python]view plain
然後運行windows的dos 命令行,切換目錄到proj1/src目錄下,輸入命令:
python convert2exe.py py2exe
Python 會生成dist文件夾,並把依賴dll 等資源拷貝到這個目錄,同時生成 app1.exe
雙擊 app1.exe 即可運行
⑹ 如何優雅地使用python採集阿里巴巴百萬商戶信息
Sublime是一款輕量文本編輯工具,可以用來快速編寫python腳本,這里就不多作介紹,詳情自己網路。本期所需的工具包是selenium,用戶需要自行安裝,可以通過pip命令快速安裝selenium,如下:
因為本人先前已經成功安裝selenium,所以這里提示「已經安裝成功」,當然要使用pip命令,必須提前安裝pip,自行網路,用戶安裝完上面的所有工具後我們就可以開始本期的裝逼之旅了。
第一步、查看www.1688.com網頁,確定抓取范圍。我們打開阿里巴巴采購首頁,我們發現阿里巴巴提供了廠商的搜索介面,如下所示:
第二步、我們試著搜索「化工」,查看得到的結果,如下:
第三步、我們可以看到,我們要的基本信息都存在了,但是聯系方式沒有,我們任意打開一個廠商的頁面,可以看到「聯系」這個導航欄項目,點擊聯系,就可以看到廠商的聯系方式,我們在將注意力放到網址url上,我們可以看到,聯系這個頁面的URL呈現規律性,如www.xxx.1688.com/page/contactinfo.htm,並且聯系電話的位置是最前的,這極大地方便了我們採集我們想要的信息,如下:
第四步、啰嗦了那麼多,直接開始我們的代碼:
首先使用python的selenium包打開一個Firefox瀏覽器窗口:
1
2
3
4
5
6
7
8
9
#! /usr/bin/env python
#coding:utf-8
from selenium import webdriver
import sys
# 解決中文報錯的問題
reload(sys)
sys.setdefaultencoding('utf-8')
driver = webdriver.Firefox()
以上程序就可以打開Firefox瀏覽器窗口,並且打開的瀏覽器窗口對象為driver,接下來我們模擬登錄,找到阿里巴巴模擬登錄的地址為,我們通這個地址模擬登錄,並通過selenium的find_element_by_name方法獲取網頁中的DOM節點,有學過JavaScript的同學應該就會了解DOM節點,具體的代碼如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
url = '
k.635.1998096057.d1'
loginUrl = 't=true&redirect_url=
3Dlogin_target_is_blank_1688%26tracelog%3Dmember_signout_signin_s_reg'
driver = webdriver.Firefox()
time.sleep(3)
driver.get(loginUrl)
time.sleep(5)
driver.find_element_by_name("TPL_username").send_keys('這里是你的淘寶賬號')
driver.find_element_by_name("TPL_password").send_keys('這里是你的淘寶密碼')
driver.find_element_by_name("TPL_password").send_keys(Keys.ENTER)
time.sleep(5)
driver.get(url)
模擬登錄成功後我們讓頁面自動跳轉到我們剛才搜索「化工」廠商的那個頁面,其中使用了time包里的sleep函數,是為了防止在網速較差的時候,網頁載入速度較慢,源碼還未下載完畢就執行查找節點的命令導致程序運行失敗。接下來我們要做的是查找廠商的主頁並找到其聯系方式,並且發現廠商找到的結果共有100頁,在這里,為了使用方便,我們直接使用for循環來模擬點擊下一頁進行採集。具體的所有源代碼如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /usr/bin/env python
#coding:utf-8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
import urllib
import urllib2
import sys
import os
import re
import csv
import numpy as np
# 解決中文報錯的問題
reload(sys)
sys.setdefaultencoding('utf-8')
csvfile = file('data.csv', 'wb')
writer = csv.writer(csvfile)
writer.writerow((u'企業名稱'.encode('gbk'), u'主頁'.encode('gbk'), u'產品'.encode('gbk')
, u'聯系人'.encode('gbk'), u'電話'.encode('gbk'), u'地址'.encode('gbk')))
url = '
635.1998096057.d1'
loginUrl = '
full_redirect=true&redirect_url=
_is_blank_1688%26tracelog%3Dmember_signout_signin_s_reg'
driver = webdriver.Firefox()
time.sleep(3)
driver.get(loginUrl)
time.sleep(5)
driver.find_element_by_name("TPL_username").send_keys('這里輸入你的淘寶賬號')
driver.find_element_by_name("TPL_password").send_keys('這里輸入你的淘寶密碼')
driver.find_element_by_name("TPL_password").send_keys(Keys.ENTER)
time.sleep(5)
driver.get(url)
time.sleep(15)
user_agents = [
'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.
0.0.11',
'Opera/9.25 (Windows NT 5.1; U; en)',
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR
2.0.50727)',
'Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Kubuntu)',
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070731 Ubuntu/dapper-se
curity Firefox/1.5.0.12',
'Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.2.9',
"Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Ubuntu/11.04 Chr
omium/16.0.912.77 Chrome/16.0.912.77 Safari/535.7",
"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0 ",
]
for page in xrange(1, 100):
try:
title = driver.find_elements_by_css_selector("a[class=list-item-title-text]")
proct = driver.find_elements_by_xpath("//div[@class=\"list-item-detail\"]/div[1]
/div[1]/a[1]")
print len(title)
pattern = re.compile('<div class="contcat-desc".*?>(.*?)</div>', re.S)
telPattern = re.compile('<dd>(.*?)</dd>', re.S)
membernamePattern = re.compile('<a.*?class="membername".*?>(.*?)</a>', re.S)
addressPattern = re.compile('"address">(.*?)</dd>', re.S)
for i in xrange(len(title)):
titleValue = title[i].get_attribute('title')
hrefValue = title[i].get_attribute('href') + 'page/contactinfo.htm'
proctValue = proct[i].text
agent = np.random.choice(user_agents)
headers = {'User-Agent' : agent, 'Accept' : '*/*', 'Referer' : ''}
request = urllib2.Request(hrefValue, headers=headers)
response = urllib2.urlopen(request)
html = response.read()
info = re.findall(pattern, html)
try:
info = info[0]
except Exception, e:
continue
tel = re.findall(telPattern, info)
try:
tel = tel[0]
tel = tel.strip()
tel = tel.replace(' ', '-')
except Exception, e:
continue
membername = re.findall(membernamePattern, html)
try:
membername = membername[0]
membername = membername.strip()
except Exception, e:
continue
address = re.findall(addressPattern, html)
try:
address = address[0]
address = address.strip()
except Exception, e:
address = ''
print 'tel:' + tel
print 'membername:' + membername
data = (titleValue.encode('gbk', 'ignore'), title[i].get_attribute('href'), pr
octValue.encode('gbk', 'ignore'), membername, tel, address)
writer.writerow(data)
for t in title:
print t.get_attribute('title')
print t.get_attribute('href') + 'page/contactinfo.htm'
print len(proct)
for p in proct:
a = repr(p.text)
a = a.encode('gbk', 'ignore')
print a
print '#' * 50
js = 'var q=document.documentElement.scrollTop=30000'
driver.execute_script(js)
time.sleep(2)
page = driver.find_elements_by_css_selector("a[class=page-next]")
page = page[0]
page.click()
time.sleep(10)
except Exception, e:
print 'error'
continue
csvfile.close()
driver.close()