1. open()

open() 以二进制流的形式读入的文件,所以读入后需要在read()和每次readline()时,做.decode('utf-8')等。
.decode('utf-8')Python 3中的 unicode 字符串中不再存在,所以会导致代码不兼容。

2. codecs.open()

codecs.open() 是网上最流行的多编码读写包,codecs.open(FILE_NAME, 'r', 'utf-8'),之后读入的都转为unicode
之前最常用这个包,但是最近遇到一些问题,比如遇到\r\n^\(换页符)等,读入会自动产生一些空行等,stackoverflow 上的一些问题:

https://stackoverflow.com/questions/12330522/reading-a-file-without-newlines

https://stackoverflow.com/questions/16130904/open-and-codecs-open-in-python-2-7-behave-strangely-different

3. io.open()

io.open()Python 2.6之后新加入的一个为Python 3写的包,暂时没有2的问题,用io.open(FILE_NAME, 'r', encoding='utf-8')
但是,遇到一个特有的问题是,fout.write()时,由于Python 3的特点,必须输出unicode。所以可能需要fout.write(string+u'\n')

~/.pip/pip.conf 中加入:

[global]
timeout = 60
index-url = https://pypi.doubanio.com/simple

I followed parts of this tutorial to setup opencv in virtualenv.

The cumbersome part is that everytime i create a virtual env, i need
to copy opencv to the lib folder. But hey, it works!

In a nutshell..

$ brew install python $ pip install numpy $ brew install opencv

$ cp /usr/local/lib/python2.7/site-packages/cv* <path-to-venv>/lib/python2.7/site-packages <path-to-venv> is the path
where you have created your virtual env.

Hope this helps.

from: https://stackoverflow.com/questions/19155603/can-opencv-be-installed-in-python-virtualenv-on-mac-mountain-lion