@@ -6,13 +6,7 @@ Python 3 FAQ
66What Python 3 versions are supported?
77-------------------------------------
88
9- PyMongo supports Python 3.x where x >= 1.
10-
11- We **do not ** support Python 3.0.x. It has many problems
12- (some that directly impact PyMongo) and was `end-of-lifed `_
13- with the release of Python 3.1.
14-
15- .. _end-of-lifed : http://www.python.org/download/releases/3.0.1/
9+ PyMongo supports Python 3.x where x >= 2.
1610
1711Are there any PyMongo behavior changes with Python 3?
1812-----------------------------------------------------
@@ -26,8 +20,8 @@ with subtype 0.
2620For example, let's insert a :class: `bytes ` instance using Python 3 then
2721read it back. Notice the byte string is decoded back to :class: `bytes `::
2822
29- Python 3.1.4 (default, Mar 21 2012, 14:34:01 )
30- [GCC 4.5 .3] on linux2
23+ Python 3.2.5 (default, Feb 26 2014, 12:40:25 )
24+ [GCC 4.7 .3] on linux2
3125 Type "help", "copyright", "credits" or "license" for more information.
3226 >>> import pymongo
3327 >>> c = pymongo.MongoClient()
@@ -39,8 +33,8 @@ read it back. Notice the byte string is decoded back to :class:`bytes`::
3933Now retrieve the same document in Python 2. Notice the byte string is decoded
4034to :class: `~bson.binary.Binary `::
4135
42- Python 2.7.3 (default, Apr 12 2012 , 10:35:17 )
43- [GCC 4.5 .3] on linux2
36+ Python 2.7.6 (default, Feb 26 2014 , 10:36:22 )
37+ [GCC 4.7 .3] on linux2
4438 Type "help", "copyright", "credits" or "license" for more information.
4539 >>> import pymongo
4640 >>> c = pymongo.MongoClient()
@@ -60,75 +54,75 @@ need to unpickle them in Python 2.
6054If you pickled an ObjectId using Python 2 and want to unpickle it using
6155Python 3 you must pass ``encoding='latin-1' `` to pickle.loads::
6256
63- Python 2.7.3 (default, Apr 12 2012 , 10:35:17 )
64- [GCC 4.5 .3] on linux2
65- Type "help", "copyright", "credits" or "license" for more information.
66- >>> import pickle
67- >>> from bson.objectid import ObjectId
68- >>> oid = ObjectId()
69- >>> oid
70- ObjectId('4f919ba2fba5225b84000000')
71- >>> pickle.dumps(oid)
72- 'ccopy_reg\n_reconstructor\np0\n(cbson.objectid\...'
73-
74- Python 3.1.4 (default, Mar 21 2012, 14:34:01 )
75- [GCC 4.5 .3] on linux2
76- Type "help", "copyright", "credits" or "license" for more information.
77- >>> import pickle
78- >>> pickle.loads(b'ccopy_reg\n_reconstructor\np0\n(cbson.objectid\...', encoding='latin-1')
79- ObjectId('4f919ba2fba5225b84000000')
57+ Python 2.7.6 (default, Feb 26 2014 , 10:36:22 )
58+ [GCC 4.7 .3] on linux2
59+ Type "help", "copyright", "credits" or "license" for more information.
60+ >>> import pickle
61+ >>> from bson.objectid import ObjectId
62+ >>> oid = ObjectId()
63+ >>> oid
64+ ObjectId('4f919ba2fba5225b84000000')
65+ >>> pickle.dumps(oid)
66+ 'ccopy_reg\n_reconstructor\np0\n(cbson.objectid\...'
67+
68+ Python 3.2.5 (default, Feb 26 2014, 12:40:25 )
69+ [GCC 4.7 .3] on linux2
70+ Type "help", "copyright", "credits" or "license" for more information.
71+ >>> import pickle
72+ >>> pickle.loads(b'ccopy_reg\n_reconstructor\np0\n(cbson.objectid\...', encoding='latin-1')
73+ ObjectId('4f919ba2fba5225b84000000')
8074
8175
8276If you need to pickle ObjectIds using Python 3 and unpickle them using Python 2
8377you must use Python 3.2.3 or newer and ``protocol <= 2 ``::
8478
85- Python 3.2.3 (v3.2.3:3d0686d90f55, Apr 10 2012, 11:25:50)
86- [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
87- Type "help", "copyright", "credits" or "license" for more information.
88- >>> import pickle
89- >>> from bson.objectid import ObjectId
90- >>> oid = ObjectId()
91- >>> oid
92- ObjectId('4f96f20c430ee6bd06000000')
93- >>> pickle.dumps(oid, protocol=2)
94- b'\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c_codecs\nencode\...'
95-
96- Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
97- [GCC 4.0.1 (Apple Computer, Inc. build 5341) ] on darwin
98- Type "help", "copyright", "credits" or "license" for more information.
99- >>> import pickle
100- >>> pickle.loads('\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c_codecs\nencode\...')
101- ObjectId('4f96f20c430ee6bd06000000')
79+ Python 3.2.3 (v3.2.3:3d0686d90f55, Apr 10 2012, 11:25:50)
80+ [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
81+ Type "help", "copyright", "credits" or "license" for more information.
82+ >>> import pickle
83+ >>> from bson.objectid import ObjectId
84+ >>> oid = ObjectId()
85+ >>> oid
86+ ObjectId('4f96f20c430ee6bd06000000')
87+ >>> pickle.dumps(oid, protocol=2)
88+ b'\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c_codecs\nencode\...'
89+
90+ Python 2.6.9 (unknown, Feb 26 2014, 12:39:10)
91+ [GCC 4.7.3 ] on linux2
92+ Type "help", "copyright", "credits" or "license" for more information.
93+ >>> import pickle
94+ >>> pickle.loads('\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c_codecs\nencode\...')
95+ ObjectId('4f96f20c430ee6bd06000000')
10296
10397
10498Unfortunately this won't work if you pickled the ObjectId using a Python 3
10599version older than 3.2.3::
106100
107- Python 3.2.2 (default, Mar 21 2012, 14:32:23)
108- [GCC 4.5.3] on linux2
109- Type "help", "copyright", "credits" or "license" for more information.
110- >>> import pickle
111- >>> from bson.objectid import ObjectId
112- >>> oid = ObjectId()
113- >>> pickle.dumps(oid, protocol=2)
114- b'\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c__builtin__\nbytes\...'
115-
116- Python 2.4.6 (#1, Apr 12 2012, 14:48:24)
117- [GCC 4.5.3] on linux3
118- Type "help", "copyright", "credits" or "license" for more information.
119- >>> import pickle
120- >>> pickle.loads('\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c__builtin__\nbytes\...')
121- Traceback (most recent call last):
122- File "<stdin>", line 1, in ?
123- File "/usr/lib/python2.4/pickle.py", line 1394, in loads
124- return Unpickler(file).load()
125- File "/usr/lib/python2.4/pickle.py", line 872, in load
126- dispatch[key](self)
127- File "/usr/lib/python2.4/pickle.py", line 1104, in load_global
128- klass = self.find_class(module, name)
129- File "/usr/lib/python2.4/pickle.py", line 1140, in find_class
130- klass = getattr(mod, name)
131- AttributeError: 'module' object has no attribute 'bytes'
101+ Python 3.2.2 (default, Mar 21 2012, 14:32:23)
102+ [GCC 4.5.3] on linux2
103+ Type "help", "copyright", "credits" or "license" for more information.
104+ >>> import pickle
105+ >>> from bson.objectid import ObjectId
106+ >>> oid = ObjectId()
107+ >>> pickle.dumps(oid, protocol=2)
108+ b'\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c__builtin__\nbytes\...'
109+
110+ Python 2.4.6 (#1, Apr 12 2012, 14:48:24)
111+ [GCC 4.5.3] on linux3
112+ Type "help", "copyright", "credits" or "license" for more information.
113+ >>> import pickle
114+ >>> pickle.loads('\x80\x02cbson.objectid\nObjectId\nq\x00)\x81q\x01c__builtin__\nbytes\...')
115+ Traceback (most recent call last):
116+ File "<stdin>", line 1, in ?
117+ File "/usr/lib/python2.4/pickle.py", line 1394, in loads
118+ return Unpickler(file).load()
119+ File "/usr/lib/python2.4/pickle.py", line 872, in load
120+ dispatch[key](self)
121+ File "/usr/lib/python2.4/pickle.py", line 1104, in load_global
122+ klass = self.find_class(module, name)
123+ File "/usr/lib/python2.4/pickle.py", line 1140, in find_class
124+ klass = getattr(mod, name)
125+ AttributeError: 'module' object has no attribute 'bytes'
132126
133127.. warning ::
134128
@@ -151,15 +145,15 @@ directory after running ``python setup.py install`` the untranslated modules
151145will be the first thing in your path. Importing pymongo will result in an
152146exception similar to::
153147
154- Python 3.1 .5 (default, Jun 2 2012 , 12:24:49 )
155- [GCC 4.6 .3] on linux2
148+ Python 3.2 .5 (default, Feb 26 2014 , 12:40:25 )
149+ [GCC 4.7 .3] on linux2
156150 Type "help", "copyright", "credits" or "license" for more information.
157151 >>> import pymongo
158152 Traceback (most recent call last):
159153 File "<stdin>", line 1, in <module>
160- File "pymongo/__init__.py", line 58 , in <module>
154+ File "pymongo/__init__.py", line 77 , in <module>
161155 version = get_version_string()
162- File "pymongo/__init__.py", line 54 , in get_version_string
156+ File "pymongo/__init__.py", line 73 , in get_version_string
163157 if isinstance(version_tuple[-1], basestring):
164158 NameError: global name 'basestring' is not defined
165159
@@ -168,11 +162,11 @@ source directory takes the untranslated modules out of your path::
168162
169163 $ cd ..
170164 $ python
171- Python 3.1 .5 (default, Jun 2 2012 , 12:24:49 )
172- [GCC 4.6 .3] on linux2
165+ Python 3.2 .5 (default, Feb 26 2014 , 12:40:25 )
166+ [GCC 4.7 .3] on linux2
173167 Type "help", "copyright", "credits" or "license" for more information.
174168 >>> import pymongo
175169 >>> pymongo.__file__
176- '/home/behackett/py3k/lib/python3.1 /site-packages/pymongo-2.2 -py3.1 -linux-x86_64.egg/pymongo/__init__.py'
170+ '/home/behackett/py3k/lib/python3.2 /site-packages/pymongo-2.7 -py3.2 -linux-x86_64.egg/pymongo/__init__.py'
177171
178172
0 commit comments