Q1 windows下安裝Scrapy出錯(cuò)cl.exe failed with exit status2解決方法
http://blog.csdn.net/u014301340/article/details/45100361; 此方案的前提是安裝VS C++ 2008. 其他版本未測試。
如果未安裝VS,而本意是安裝在win10,64位,python3.6環(huán)境下安裝pycrypto, 最后通過http://stackoverflow.com/questions/41813030/problems-with-installation-pycrypto-in-python-3-6提供的方法安裝pycryptodome解決問題。
Q2?TypeError:Only byte strings can be passed to C code
http://blog.csdn.net/tracey2012/article/details/45287851
“文本總是Unicode,由str類型表示,二進(jìn)制數(shù)據(jù)則由bytes類型表示。Python 3不會(huì)以任意隱式的方式混用str和bytes,正是這使得兩者的區(qū)分特別清晰。你不能拼接字符串和字節(jié)包,也無法在字節(jié)包里搜索字符串(反之亦然),也不能將字符串傳入?yún)?shù)為字節(jié)包的函數(shù)(反之亦然)。” 用bytes函數(shù)轉(zhuǎn)換strings。
Q3 name 'unicode' is not defined
http://stackoverflow.com/questions/36110598/nameerror-name-unicode-is-not-defined
There is no such name in Python 3, no. You are trying to run Python 2 code in Python 3. In Python 3,unicodehas been renamed to str.
Q4 下載numpy?1.12.1+mkl?cp36?cp36m?win_amd64.whl文件安裝報(bào)錯(cuò) is not a valid wheel filename.?
參考http://blog.csdn.net/yxpyxp12341234/article/details/70436854?
文件名改為 numpy-1.12.1-cp36-none-win_amd64.whl 成功安裝。
Q5 matplotlib生成的字體無法正常顯示
指定字體 如: mpl.rcParams['font.sans-serif']=['SimHei']#指定默認(rèn)字體
Q6 中文字符顯示問題
A.Python源代碼內(nèi)默認(rèn)不能有中文,包括注釋。解決方法是在代碼一開頭加上:
# -*- coding: gbk -*-
或
# -*- coding: utf-8 -*-
具體選哪一種看具體情況——與編輯器保存時(shí)所使用的編碼相關(guān)。一般來講,如果不是網(wǎng)絡(luò)編程,統(tǒng)一用utf-8就OK了,包括與MySQL的交互也可以用utf-8搞定。如果是網(wǎng)絡(luò)編譯,特別是與FTP打交道,推薦使用gbk,可以省去很多麻煩。
注意本法沒有涉及不同編碼的轉(zhuǎn)換。
Q7 當(dāng)html中的元素有多個(gè)class(如 <div class="menu top" ></div>?) lxml 的xpath無法通過單個(gè)class或id定位到元素:
如 selector.xpath('//div[@class="menu"]') 將返回[ ]
需要類名齊全才能正確定位元素:
selector.xpath('//div[@class="menu top"]')?
同時(shí)有id和class時(shí)(如<div id="top" class="menu"></div ),通過任一屬性均可定位到元素:
selector.xpath('//div[@id="top"]') 或 selector.xpath('//div[@class="menu"]') ?
Q8 lxml的xpath根據(jù)屬性定位對(duì)除去div,的元素不起作用,如根據(jù)class="left"、href="index.html"均無法定位到a元素,p同樣不起作用。
Q8 安裝Anaconda忘記設(shè)置環(huán)境變量
手動(dòng)添加環(huán)境變量:在用戶變量中,PATH添加C:\Anaconda;C:\Anaconda\Scripts;
參考 http://blog.csdn.net/gaohuazhao/article/details/52685190
Q9 Anaconda添加國內(nèi)鏡像
設(shè)置國內(nèi)鏡像:清華TUNA鏡像源有Anaconda倉庫的鏡像,我們將其加入conda的配置即可:
# 添加Anaconda的TUNA鏡像
condaconfig--addchannelshttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# TUNA的help中鏡像地址加有引號(hào),需要去掉
# 設(shè)置搜索時(shí)顯示通道地址
condaconfig--setshow_channel_urlsyes
參考 http://python.jobbole.com/86236/