{"id":1589,"date":"2019-10-13T14:34:34","date_gmt":"2019-10-13T21:34:34","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/"},"modified":"2019-10-13T14:34:34","modified_gmt":"2019-10-13T21:34:34","slug":"tips-and-tricks-for-upgrading-from-python-2-to-python-3","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/es\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/","title":{"rendered":"How to Update Python 2 to Python 3 &amp; The Differences Between Them"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><span>Introduction<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span>The last major Python upgrade &#8212; to version 3 &#8212; arrived in Dec. 2008, nearly 12 years ago. And yet there is a good chance that you are still working on the Python 2 product or test code. If so, then you may be\u00a0 seeing the below deprecation message as a reminder to update the Python version you&#8217;re working with.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>&#8220;DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won\u2019t be maintained after that date. A future version of pip will drop support for Python 2.7.&#8221;<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Please take this seriously and plan accordingly: Python updates to 3.x are not backward compatible. What you write with Python 2.x versions may not function properly when using 3.x<\/span><span>.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Be sure to also read the fine print. According to the website for the programming language, the final Python upgrade release date is still TBD: \u201cBeing the last of the 2.x series, 2.7 will receive bugfix support until 2020. Support officially stops January 1 2020, but the final release will occur after that date.\u201d [<a href=\"https:\/\/www.python.org\/dev\/peps\/pep-0373\/#update\">1<\/a>]<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>So, Python 2 is entering into unsupported mode by the end of this year. If you haven\u2019t yet done so, now is a good time to migrate the current Python 2 code to Python 3 syntax and stick to Python 3 going forward. <\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Why don\u2019t teams just jump start on this Python 2 to 3 migration? One of the major hurdles is that the majority of working code simply breaks (read more at <\/span><a href=\"https:\/\/python-notes.curiousefficiency.org\/en\/latest\/python3\/questions_and_answers.html#why-was-python-3-made-incompatible-with-python-2\"><span>why-was-python-3-made-incompatible-with-python-2<\/span><\/a><span>), either because of the direct language syntax or issues with third party APIs. Let\u2019s be fair here: few of us would bother with migration if the new Python updates were backwards compatible. Instead, version 2 will go unsupported, forcing many &#8212; including us here at Couchbase &#8212; to prioritize migration. Even if the team crosses the bug fix support deadline, it&#8217;s ok (because your code is still working). As a team, we decided it\u2019s better to migrate as close to this date as possible so that we are on the same page with other Python community members and learn alongside them.\u00a0\u00a0<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>This document is a collection of tips and tricks we learned while upgrading to Python 3 along with common problems we encountered during the Couchbase test infra migration process. As you&#8217;ll see we manually update python by command line after kick-starting with an automated process. Your approach may be different. Regardless, start as soon as you can. Updating python from version 2 to version 3 is important.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.couchbase.com\/downloads\/\"><span>Couchbase<\/span><\/a><span> is an open source Enterprise-class MultiCloud to Edge NoSQL Database. The Couchbase functional testing framework, TestRunner has been developed in Python 2. The TestRunner git\u00a0 repository can be found at<\/span><a href=\"https:\/\/github.com\/couchbase\/testrunner\"> <span>https:\/\/github.com\/couchbase\/testrunner<\/span><\/a><span> .\u00a0 Our goal now is to completely switch to Python 3 runtime instead of co-running with both Python 3 and Python 2.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>As part of the Python upgrade process, we have identified the major changes needed to successfully port to version 3. Some of the problems you&#8217;ll read about we identified during the porting process. Our aim in sharing our learnings is to help you with your own migration. You can pick the latest Python 3.x version (it depends on the pre-release, stable, security-fixes version on a specific platform, 3.7 or 3.6), which we are referring to as Python 3 throughout this blog. See more details on the release at <\/span><a href=\"https:\/\/www.python.org\/downloads\/\"><span>Python releases download<\/span><\/a><span> and\u00a0 <\/span><span><a href=\"https:\/\/docs.python.org\/3\">Python 3 documentation<\/a>.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cheat Sheet<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span>Major Changes: Python 2 vs. Python 3<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To get an idea of the key differences between Python 2 and Python 3, here is the summary list of code changes needed.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table border=\"1\">\n<tbody>\n<tr>\n<td><b>Python 2<\/b><\/td>\n<td><b>Python 3<\/b><\/td>\n<\/tr>\n<tr>\n<td><span>Text utf-8 : str<\/span><br>\n<span>&#8216;<\/span><span>&#8216;<\/span><\/td>\n<td><span>Text is unicode : str<\/span><br>\n<span>u&#8221;<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>Binary is same as Text: bytes\/str<\/span><br>\n<span>Example:<\/span><br>\n<span>file.read(6) == &#8216;GIF89a&#8217;<\/span><\/td>\n<td><span>Binary data is represented as b prefix: bytes<\/span><br>\n<span>\u00a0b&#8221;<\/span><br>\n<span>Use decode() to get the string, encode() to get bytes.<\/span><span>Examples:\u00a0<\/span><br>\n<span>file.read(6) == b&#8217;GIF89a&#8217;<\/span><br>\n<span>b&#8217;hello&#8217;.decode() \u2192 &#8216;hello&#8217;<\/span><br>\n<span>\u2018hello\u2019.encode() \u2192 b&#8217;hello&#8217;<\/span><br>\n<span><span>str(b\u2019hello\u2019) \u2192 &#8220;b&#8217;hello&#8217;<\/span><\/span>&#8220;<\/td>\n<\/tr>\n<tr>\n<td><span>Print statement<\/span><br>\n<span>Example: print &#8216; &#8216;<\/span><\/td>\n<td><span>Print function<\/span><br>\n<span>Example:print(&#8216; &#8216;)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>Integer division<\/span><br>\n<span>Example: 5\/2=2<\/span><\/td>\n<td><span>Floor Division. Use 2 slashes<\/span><br>\n<span>Example: 5\/\/2 = 2 and 5\/2=2.5<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>Float division<\/span><br>\n<span>Example: 5\/2.0 = 2.5 or 5.0\/2 = 2.5<\/span><\/td>\n<td><span>Float Division. Use single slash<\/span><br>\n<span>Example: 5\/2 = 2.5<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>Long type is different from int<\/span><br>\n<span>long\u00a0<\/span><\/td>\n<td><span>There is no long type. It is same as int<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>xrange()<\/span><\/td>\n<td><span>range()<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>Iteration functions had iter prefix. iterxxx()<\/span><br>\n<span>Example: iteritems()<\/span><\/td>\n<td><span>Dropped iter prefix. xxxx()<\/span><br>\n<span>Example: items()<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>Lists are directly loaded (all elements loaded into memory when list is used)<\/span><br>\n<span>Example: for i in []\u00a0<\/span><\/td>\n<td><span>Lists are lazy loaded (when an element is accessed, then only loaded into memory)<\/span><br>\n<span>Example: for i in list([])\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>Dictionaries can be compared by default or against 2 dict.<\/span><br>\n<span>Example: sorted(dict)\u00a0<\/span><\/td>\n<td><span>Dictionaries can\u2019t be compared directly. sorted() should have key.<\/span>\n<p><span>Example: <\/span><span>sorted(expected_result,key=(lambda x: x[bucket.name][&#8216;name&#8217;]))<\/span><span>For general dict\/list comparison, you can use below:\u00a0<\/span><br>\n<span>\u00a0from deepdiff import DeepDiff<\/span><br>\n<span>\u00a0<\/span><span>diffs = DeepDiff(actual_result[&#8216;results&#8217;], expected_result[<\/span><b>&#8216;results&#8217;<\/b><span>], <\/span><span>ignore_order<\/span><span>=<\/span><b>True<\/b><span>)<\/span><b>if <\/b><span>diffs:<\/span><br>\n<span>\u00a0\u00a0\u00a0<\/span><span>self<\/span><span>.assertTrue(<\/span><b>False<\/b><span>, diffs)<\/span><\/p>\n<p><span>Bytes and strings as values:<\/span><br>\n<span>diffs = DeepDiff(<\/span><span>set<\/span><span>(actual_indexes), <\/span><span>set<\/span><span>(indexes_names), <\/span><span>ignore_order<\/span><span>=<\/span><b>True<\/b><span>, <\/span><span>ignore_string_type_changes<\/span><span>=<\/span><b>True<\/b><span>)<\/span><\/p><\/td>\n<\/tr>\n<tr>\n<td><span>string.replace(data[i],&#8230;)<\/span><\/td>\n<td><span>data[i].replace(..)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>urllib.urlencode()<\/span><\/td>\n<td><span>New modules<\/span>\n<ul>\n<li><span>http.client<\/span><\/li>\n<li><span>urllib.request, urllib.error, urllib.parse<\/span><\/li>\n<li><span>sgmllib3k<\/span><\/li>\n<\/ul>\n<p><span>Examples:\u00a0<\/span><br>\n<span>urllib.parse.urlencode()<\/span><\/p><\/td>\n<\/tr>\n<tr>\n<td><span>string.lowercase<\/span><\/td>\n<td><span>Attributes:<\/span><br>\n<span>string.ascii_lowercase<\/span><br>\n<span>string.ascii_uppercase<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><span>See the <\/span><a href=\"https:\/\/github.com\/couchbaselabs\/testrunner-py3\/commits\/master\"><span>testrunner py3 commits<\/span><\/a><span>\u00a0 for changes<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><span>Python 3 Setup<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span>To setup Python 3 from scratch, run the below commands on a new host with major supported platforms.<\/span><br>\n<span>Later during the runtime, either use python 3 command or python in python 3 virtual env. Use either pip3 or pip3.x (pip3.6 for example) to install packages based on the installed Python 3 version.<\/span><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table>\n<tbody>\n<tr>\n<td><b>Mac OS<\/b><br>\n(Example: Your laptop)<br>\n<span>Direct setup (pip3 automatically installed):<\/span>(https:\/\/wsvincent.com\/install-python3-mac\/)\n<p><p>[crayon lang=&#8221;python&#8221; decode=&#8221;true&#8221;]brew install python3[\/crayon]<\/p>\n<\/p>\n<p><span>Virtual environment setup:<\/span><\/p>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install virtualenv<br \/>\n$ mkdir ~\/environments<br \/>\n$ virtualenv -p python3 ~\/environments<br \/>\n$ source ~\/environments\/bin\/activate<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n$ python -V<br \/>\nPython 3.7.3<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n[\/crayon]<\/p>\n<\/p>\n<p>Install required libraries:<\/p>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install couchbase<br \/>\n$ pip3 install sgmllib3k<br \/>\n$ pip3 install paramiko<br \/>\n$ pip3 install httplib2<br \/>\n$ pip3 install pyyaml<br \/>\n$ pip3 install Geohash<br \/>\n$ pip3 install python-geohash<br \/>\n$ pip3 install deepdiff<br \/>\n$ pip3 install pyes<\/p>\n<p>[\/crayon]<\/p>\n<\/p>\n<p>For now, the below modification is required to the common Python 3 http client otherwise, you would hit an error.<\/p>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n<\/p>\n<p>\u00a0<\/p><\/td>\n<\/tr>\n<tr>\n<td><b>CentOS\u00a0\u00a0<\/b><br>\n(<span>Example node: Jenkins Slave)<\/span><br>\nDirect setup and virtual environment:\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\n# yum list available &gt; \/tmp\/available_pkgs.txt<br \/>\n# cat \/tmp\/available_pkgs.txt\u00a0 |egrep python3<br \/>\n# yum -y install python36u<br \/>\n# python3.6 &#8211;version<br \/>\n# yum -y install python36u-pip<br \/>\n# yum -y install python36u-devel<br \/>\n# python3.6 -V<br \/>\n# mkdir ~\/environments<br \/>\n# cd ~\/environments\/<br \/>\n# python3.6 -m venv my_env<br \/>\n# source ~\/environments\/my_env\/bin\/activate<br \/>\n# python -V[\/crayon]<\/p>\n<\/p>\n<p>Install required libraries:<\/p>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# pip3.6 install requests<br \/>\n# pip3.6 install sgmllib3k<br \/>\n# pip3.6 install paramiko<br \/>\n# pip3.6 install httplib2<br \/>\n# pip3.6 install pyyaml<br \/>\n# pip3.6 install pytz<br \/>\n# pip3.6 install Geohash<br \/>\n# pip3.6 install python-geohash<br \/>\n# pip3.6 install deepdiff<br \/>\n# pip3.6 install pyes[\/crayon]<\/p>\n<\/p>\n<p>\u00a0<\/p>\n<p><span>Perform Couchbase CSDK and Python SDK installation on new slave:<\/span><\/p>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install wget git<br \/>\n# wget https:\/\/packages.couchbase.com\/releases\/couchbase-release\/couchbase-release-1.0-6-x86_64.rpm<br \/>\n# rpm -iv couchbase-release-1.0-6-x86_64.rpm<br \/>\n# yum install libcouchbase-devel libcouchbase2-bin gcc gcc-c++<br \/>\n# pip3.6 install couchbase[\/crayon]<\/p>\n<\/p>\n<p>For now, the below modification is required to the common Python 3 http client otherwise, you would hit an error.<\/p>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n<\/p>\n<p>\u00a0<\/p><\/td>\n<\/tr>\n<tr>\n<td><b>Ubuntu slave using for Python 3 runtime verification<\/b><br>\nDirect Setup:\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# apt install python3-pip[\/crayon]<\/p>\n<\/p>\n<p>\u00a0<\/p>\n<p>Install the required libraries:<\/p>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# pip3 install sgmllib3k<br \/>\n# pip3 install paramiko<br \/>\n# pip3 install httplib2<br \/>\n# pip3 install pyyaml<br \/>\n# pip3 install pytz (NOTE: used by xdcr tests)<br \/>\n# pip3 install Geohash<br \/>\n# pip3 install python-geohash<br \/>\n# pip3 install deepdiff<br \/>\n# pip3 install pyes[\/crayon]<\/p>\n<\/p>\n<p><span>Install CSDK and Python SDK installation: (Ref:<\/span><span>\u00a0<\/span><a href=\"https:\/\/docs.couchbase.com\/c-sdk\/2.10\/start-using-sdk.html\"><span>https:\/\/docs.couchbase.com\/c-sdk\/2.10\/start-using-sdk.html )<\/span><\/a><\/p>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install virtualenv<br \/>\n$ mkdir ~\/environments<br \/>\n$ virtualenv -p python3 ~\/environments<br \/>\n$ source ~\/environments\/bin\/activate<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n$ python -V<br \/>\nPython 3.7.3<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n[\/crayon]<\/p>\n0<\/p>\n<p>For now, the below modification is required to the common Python 3 http client otherwise, you would hit an error.<\/p>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install virtualenv<br \/>\n$ mkdir ~\/environments<br \/>\n$ virtualenv -p python3 ~\/environments<br \/>\n$ source ~\/environments\/bin\/activate<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n$ python -V<br \/>\nPython 3.7.3<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n[\/crayon]<\/p>\n1<\/p>\n<p>\u00a0<\/p><\/td>\n<\/tr>\n<tr>\n<td><b>Windows<\/b><br>\n<span>Download and install: <\/span><a href=\"https:\/\/www.python.org\/ftp\/python\/3.7.4\/python-3.7.4.exe\"><span>https:\/\/www.python.org\/ftp\/python\/3.7.4\/python-3.7.4.exe<\/span><\/a>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install virtualenv<br \/>\n$ mkdir ~\/environments<br \/>\n$ virtualenv -p python3 ~\/environments<br \/>\n$ source ~\/environments\/bin\/activate<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n$ python -V<br \/>\nPython 3.7.3<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n[\/crayon]<\/p>\n2<\/p>\n<p>Install required libraries:<\/p>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install virtualenv<br \/>\n$ mkdir ~\/environments<br \/>\n$ virtualenv -p python3 ~\/environments<br \/>\n$ source ~\/environments\/bin\/activate<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n$ python -V<br \/>\nPython 3.7.3<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n[\/crayon]<\/p>\n3<\/p>\n<p>\u00a0<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span>Porting Process<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">At a high level, the porting is a three step process. 1) Auto conversion 2) Manual changes 3) Runtime validation and fix<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At first, clone the original repository and have the basic automatic conversion changes. Checkin the changes as a new repository until full conversion is done. This way, the current regression cycles can go without interruption.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span>1. Auto conversion<\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><span>There is an automated tool called <\/span><a href=\"https:\/\/docs.python.org\/2\/library\/2to3.html#\"><span>2to3<\/span><\/a> tool<span>, provided by the Python 3 team that helps in taking care of a few common patterns like print, exception, list wrapping, relative imports etc.\u00a0\u00a0<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>You can start with a single directory in the locally cloned workspace to do double check. Later, the conversion can be done entirely on entire code so that basic porting is taken care of.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Below are some of the sample 2to3 conversion commands on the MacOS. In the last command, note that all idioms were applied. This way, the first time conversion can take care of key changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install virtualenv<br \/>\n$ mkdir ~\/environments<br \/>\n$ virtualenv -p python3 ~\/environments<br \/>\n$ source ~\/environments\/bin\/activate<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n$ python -V<br \/>\nPython 3.7.3<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n[\/crayon]<\/p>\n4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span>2. Manual changes<\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><span>The auto conversion doesn\u2019t do the complete porting. The below common problems might be experienced during the porting process than the common syntax changes done by the auto conversion 2to3 tool.\u00a0<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Run the test class and see if there are any errors and fix appropriately, deciding whether to switch from bytes to str or str to bytes or some sort\/comparison issue where one has to fix the key name in the sorted function. This is an iterative process until all the code runtime has been validated.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Once a common pattern for sure is clear, then you can do grep and sed to replace across many class files. If you are not sure about other code until runtime, then defer until that test class is executed.\u00a0<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>There might be issues with third party libraries\/modules might have changed, those need to be searched on the web and used appropriately.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Make sure all the code path is covered by running across all supported platforms and parameters.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Runtime Validation and Fix<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Once the conversion is done, then perform a lot of code runtime as Python is a dynamic language. Otherwise, the changes can break the things if you do just visual static code inspection\/changes. You can start with basic sanity tests, acceptance tests and then select full tests from a single module of tests. <\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Once you&#8217;re comfortable, then go with all other modules one by one. Keep checking in the changes to the new repository. In addition, you need to make sure there are no regressions with ported changes from this new repository by running sanity tests on the newer builds. Also, the validation should include all the supported platforms with Python 3.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span>Python 3 Ported Code and Status<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Below is where to find the new repository for Python 3 ported code until it is merged to the main repository. The plan is to do one cycle of porting or intermediately take the changes from the main repo and do a manual merge to this.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/couchbaselabs\/testrunner-py3\/\"><span>https:\/\/github.com\/couchbaselabs\/testrunner-py3\/<\/span><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>(Branch: master)<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Many common changes were already done but not completed as there might be some other runtime issues. Fixes in common can also be regressed to the earlier fixes because of assumptions on input value type conversions. There is still some more ported code to be validated with Python 3 and the effort is still in progress.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, let me show you the common issues <span>that occurred<\/span> during the runtime validation. You can use this as a reference when you hit an issue to see if you are having the similar issue. You can apply the same solution and see if it works for you. <span>And if you have any<\/span> new ideas, you can put them in the comments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span>Common Runtime Problems<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span>\u00a0<\/span><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>1. Problem(s): <\/span><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span>You might get some of the below TypeErrors during runtime like str instead of bytes and bytes instead of str<\/span><\/li>\n\n\n<li><span>Error#1. TypeError: can&#8217;t concat str to bytes<\/span><\/li>\n\n\n<li><span>Error#2. TypeError: must be str, not bytes<\/span>\n<ul>\n<li>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install virtualenv<br \/>\n$ mkdir ~\/environments<br \/>\n$ virtualenv -p python3 ~\/environments<br \/>\n$ source ~\/environments\/bin\/activate<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n$ python -V<br \/>\nPython 3.7.3<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n[\/crayon]<\/p>\n5<\/p>\n<\/li>\n<\/ul>\n<\/li>\n\n\n<li><span>Error#3. TypeError: a bytes-like object is required, not &#8216;str&#8217;<\/span>\n<ul>\n<li>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install virtualenv<br \/>\n$ mkdir ~\/environments<br \/>\n$ virtualenv -p python3 ~\/environments<br \/>\n$ source ~\/environments\/bin\/activate<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n$ python -V<br \/>\nPython 3.7.3<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n[\/crayon]<\/p>\n6<\/p>\n<\/li>\n<\/ul>\n<\/li>\n\n\n<li><span>Error#4. TypeError: Cannot mix str and non-str arguments<\/span>\n<ul>\n<li>\n<p><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install virtualenv<br \/>\n$ mkdir ~\/environments<br \/>\n$ virtualenv -p python3 ~\/environments<br \/>\n$ source ~\/environments\/bin\/activate<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n$ python -V<br \/>\nPython 3.7.3<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n[\/crayon]<\/p>\n7<\/p>\n<\/li>\n<\/ul>\n<\/li>\n\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>See the types of the variables in the statement and use xxx.encode() to get the bytes or xxx.decode() to get the string or use b prefix or use str(). Sometimes, the input might not be unknown and in this case, use try x.encode() except AttributeError: pass<\/span><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span><br>\n<\/span><span>2. Problem(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>TypeError: <\/span><span>root &#8211; ERROR &#8211; &#8212;&#8212;-&gt;installation failed: a bytes-like object is required, not &#8216;str&#8217;<\/span><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):\u00a0 <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>In this case, add b as prefix to the string under comparison or change the byte type to string type. Example: lib\/remote\/remote_util.py<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install virtualenv<br \/>\n$ mkdir ~\/environments<br \/>\n$ virtualenv -p python3 ~\/environments<br \/>\n$ source ~\/environments\/bin\/activate<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n$ python -V<br \/>\nPython 3.7.3<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n[\/crayon]<\/p>\n8<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Surround with try-except to check the exact line causing the error (say above TypeError.)\u00a0<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install virtualenv<br \/>\n$ mkdir ~\/environments<br \/>\n$ virtualenv -p python3 ~\/environments<br \/>\n$ source ~\/environments\/bin\/activate<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n$ python -V<br \/>\nPython 3.7.3<br \/>\n(environments) jmunta-mac:~ jagadeshmunta<br \/>\n[\/crayon]<\/p>\n9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Sample output after traceback.print_exec() to see the full stack trace in similar to java.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fix with changes to lib\/remote\/remote_util.py as below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install couchbase<br \/>\n$ pip3 install sgmllib3k<br \/>\n$ pip3 install paramiko<br \/>\n$ pip3 install httplib2<br \/>\n$ pip3 install pyyaml<br \/>\n$ pip3 install Geohash<br \/>\n$ pip3 install python-geohash<br \/>\n$ pip3 install deepdiff<br \/>\n$ pip3 install pyes<\/p>\n<p>[\/crayon]<\/p>\n0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><\/h4>\n\n\n\n<h4 class=\"wp-block-heading\"><span>3. Problem(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install couchbase<br \/>\n$ pip3 install sgmllib3k<br \/>\n$ pip3 install paramiko<br \/>\n$ pip3 install httplib2<br \/>\n$ pip3 install pyyaml<br \/>\n$ pip3 install Geohash<br \/>\n$ pip3 install python-geohash<br \/>\n$ pip3 install deepdiff<br \/>\n$ pip3 install pyes<\/p>\n<p>[\/crayon]<\/p>\n1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install couchbase<br \/>\n$ pip3 install sgmllib3k<br \/>\n$ pip3 install paramiko<br \/>\n$ pip3 install httplib2<br \/>\n$ pip3 install pyyaml<br \/>\n$ pip3 install Geohash<br \/>\n$ pip3 install python-geohash<br \/>\n$ pip3 install deepdiff<br \/>\n$ pip3 install pyes<\/p>\n<p>[\/crayon]<\/p>\n2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>4. Problem(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>AttributeError suite_setUp() or suite_tearDown() are missing for some testsuites.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install couchbase<br \/>\n$ pip3 install sgmllib3k<br \/>\n$ pip3 install paramiko<br \/>\n$ pip3 install httplib2<br \/>\n$ pip3 install pyyaml<br \/>\n$ pip3 install Geohash<br \/>\n$ pip3 install python-geohash<br \/>\n$ pip3 install deepdiff<br \/>\n$ pip3 install pyes<\/p>\n<p>[\/crayon]<\/p>\n3<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Add the dummy suite_setUp() and suite_tearDown() methods.\u00a0<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install couchbase<br \/>\n$ pip3 install sgmllib3k<br \/>\n$ pip3 install paramiko<br \/>\n$ pip3 install httplib2<br \/>\n$ pip3 install pyyaml<br \/>\n$ pip3 install Geohash<br \/>\n$ pip3 install python-geohash<br \/>\n$ pip3 install deepdiff<br \/>\n$ pip3 install pyes<\/p>\n<p>[\/crayon]<\/p>\n4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>5. Problem(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install couchbase<br \/>\n$ pip3 install sgmllib3k<br \/>\n$ pip3 install paramiko<br \/>\n$ pip3 install httplib2<br \/>\n$ pip3 install pyyaml<br \/>\n$ pip3 install Geohash<br \/>\n$ pip3 install python-geohash<br \/>\n$ pip3 install deepdiff<br \/>\n$ pip3 install pyes<\/p>\n<p>[\/crayon]<\/p>\n5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install couchbase<br \/>\n$ pip3 install sgmllib3k<br \/>\n$ pip3 install paramiko<br \/>\n$ pip3 install httplib2<br \/>\n$ pip3 install pyyaml<br \/>\n$ pip3 install Geohash<br \/>\n$ pip3 install python-geohash<br \/>\n$ pip3 install deepdiff<br \/>\n$ pip3 install pyes<\/p>\n<p>[\/crayon]<\/p>\n6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>6. Problem(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>AttributeError: &#8216;Transport&#8217; object has no attribute &#8216;_Thread__stop&#8217;<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install couchbase<br \/>\n$ pip3 install sgmllib3k<br \/>\n$ pip3 install paramiko<br \/>\n$ pip3 install httplib2<br \/>\n$ pip3 install pyyaml<br \/>\n$ pip3 install Geohash<br \/>\n$ pip3 install python-geohash<br \/>\n$ pip3 install deepdiff<br \/>\n$ pip3 install pyes<\/p>\n<p>[\/crayon]<\/p>\n7<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>There is no direct stopping of a non-daemonic thread. But syntax-wise use t._stop(). The recommendation is to use the graceful shutdown using a global flag and check in the thread\u2019s run() to break.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>(<\/span><a href=\"https:\/\/stackoverflow.com\/questions\/27102881\/python-threading-self-stop-event-object-is-not-callable\"><span>https:\/\/stackoverflow.com\/questions\/27102881\/python-threading-self-stop-event-object-is-not-callable<\/span><\/a><span>)<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span>7. Problem(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Test expirytests.ExpiryTests.test_expired_keys was not found: module &#8216;string&#8217; has no attribute &#8216;translate&#8217;<\/span><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Rewrite with str static methods. There is no old way of getting all chars, so we used the earlier code and used total set.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>vi lib\/membase\/api\/tap.py\u00a0<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install couchbase<br \/>\n$ pip3 install sgmllib3k<br \/>\n$ pip3 install paramiko<br \/>\n$ pip3 install httplib2<br \/>\n$ pip3 install pyyaml<br \/>\n$ pip3 install Geohash<br \/>\n$ pip3 install python-geohash<br \/>\n$ pip3 install deepdiff<br \/>\n$ pip3 install pyes<\/p>\n<p>[\/crayon]<\/p>\n8<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>8. Problem(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>TabError: inconsistent use of tabs and spaces in indentation<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ pip3 install couchbase<br \/>\n$ pip3 install sgmllib3k<br \/>\n$ pip3 install paramiko<br \/>\n$ pip3 install httplib2<br \/>\n$ pip3 install pyyaml<br \/>\n$ pip3 install Geohash<br \/>\n$ pip3 install python-geohash<br \/>\n$ pip3 install deepdiff<br \/>\n$ pip3 install pyes<\/p>\n<p>[\/crayon]<\/p>\n9<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Search for tab characters and replace with space characters.\u00a0<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>For the above issue, remove tab characters.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>9. Problem(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n1<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Case sensitiveness issue. Fixed by changing from x_couchbase_meta key to X_Couchbase_Meta<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>10. Problem(s): <\/span><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span>Error#1. TypeError: &#8216;&lt;&#8216; not supported between instances of &#8216;dict&#8217; and &#8216;dict&#8217;<\/span><\/li>\n\n\n<li><span>Error#2. TypeError: &#8216;cmp&#8217; is an invalid keyword argument for this function<\/span><\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n2<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>\u00a0\u00a0\u00a0<\/span><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>11. Problem(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n4<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>12. Problem(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n6<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n7<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>13. Problem(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n8<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Here, it should return int as python 3 doesn\u2019t compare automatically as in python 2.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>14. Problem(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]$ vi \/usr\/lib64\/python3.6\/http\/client.py\u00a0\u00a0<br \/>\nchunk to chunk.encode() in similar to the below:<br \/>\n1078 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 chunk = f'{len(chunk):X}rn&#8217;.encode(&#8216;ascii&#8217;) + chunk.encode() [\/crayon]<\/p>\n9<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\n# yum list available &gt; \/tmp\/available_pkgs.txt<br \/>\n# cat \/tmp\/available_pkgs.txt\u00a0 |egrep python3<br \/>\n# yum -y install python36u<br \/>\n# python3.6 &#8211;version<br \/>\n# yum -y install python36u-pip<br \/>\n# yum -y install python36u-devel<br \/>\n# python3.6 -V<br \/>\n# mkdir ~\/environments<br \/>\n# cd ~\/environments\/<br \/>\n# python3.6 -m venv my_env<br \/>\n# source ~\/environments\/my_env\/bin\/activate<br \/>\n# python -V[\/crayon]<\/p>\n0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>15. Problem(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\n# yum list available &gt; \/tmp\/available_pkgs.txt<br \/>\n# cat \/tmp\/available_pkgs.txt\u00a0 |egrep python3<br \/>\n# yum -y install python36u<br \/>\n# python3.6 &#8211;version<br \/>\n# yum -y install python36u-pip<br \/>\n# yum -y install python36u-devel<br \/>\n# python3.6 -V<br \/>\n# mkdir ~\/environments<br \/>\n# cd ~\/environments\/<br \/>\n# python3.6 -m venv my_env<br \/>\n# source ~\/environments\/my_env\/bin\/activate<br \/>\n# python -V[\/crayon]<\/p>\n1<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Converted the key to string so that ch is string instead of int with binary key. See the file.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\n# yum list available &gt; \/tmp\/available_pkgs.txt<br \/>\n# cat \/tmp\/available_pkgs.txt\u00a0 |egrep python3<br \/>\n# yum -y install python36u<br \/>\n# python3.6 &#8211;version<br \/>\n# yum -y install python36u-pip<br \/>\n# yum -y install python36u-devel<br \/>\n# python3.6 -V<br \/>\n# mkdir ~\/environments<br \/>\n# cd ~\/environments\/<br \/>\n# python3.6 -m venv my_env<br \/>\n# source ~\/environments\/my_env\/bin\/activate<br \/>\n# python -V[\/crayon]<\/p>\n2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>16. Problem(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>TypeError: &#8216;FileNotFoundError&#8217; object is not sub-scriptable<\/span><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Changed in Python 3 as FileNotFoundError is not sub-scriptable and instead, use errno attribute,\u00a0 e.errno<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\n# yum list available &gt; \/tmp\/available_pkgs.txt<br \/>\n# cat \/tmp\/available_pkgs.txt\u00a0 |egrep python3<br \/>\n# yum -y install python36u<br \/>\n# python3.6 &#8211;version<br \/>\n# yum -y install python36u-pip<br \/>\n# yum -y install python36u-devel<br \/>\n# python3.6 -V<br \/>\n# mkdir ~\/environments<br \/>\n# cd ~\/environments\/<br \/>\n# python3.6 -m venv my_env<br \/>\n# source ~\/environments\/my_env\/bin\/activate<br \/>\n# python -V[\/crayon]<\/p>\n3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>17. Problem(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\n# yum list available &gt; \/tmp\/available_pkgs.txt<br \/>\n# cat \/tmp\/available_pkgs.txt\u00a0 |egrep python3<br \/>\n# yum -y install python36u<br \/>\n# python3.6 &#8211;version<br \/>\n# yum -y install python36u-pip<br \/>\n# yum -y install python36u-devel<br \/>\n# python3.6 -V<br \/>\n# mkdir ~\/environments<br \/>\n# cd ~\/environments\/<br \/>\n# python3.6 -m venv my_env<br \/>\n# source ~\/environments\/my_env\/bin\/activate<br \/>\n# python -V[\/crayon]<\/p>\n4<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s):<\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>The nested dictionary\/list comparison was not working because of the earlier sorted function to sort completely is now not available. Use deepdiff module and DeepDiff class to do the comparison<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>18. Problem(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>AttributeError: module &#8216;string&#8217; has no attribute &#8216;replace&#8217;<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\n# yum list available &gt; \/tmp\/available_pkgs.txt<br \/>\n# cat \/tmp\/available_pkgs.txt\u00a0 |egrep python3<br \/>\n# yum -y install python36u<br \/>\n# python3.6 &#8211;version<br \/>\n# yum -y install python36u-pip<br \/>\n# yum -y install python36u-devel<br \/>\n# python3.6 -V<br \/>\n# mkdir ~\/environments<br \/>\n# cd ~\/environments\/<br \/>\n# python3.6 -m venv my_env<br \/>\n# source ~\/environments\/my_env\/bin\/activate<br \/>\n# python -V[\/crayon]<\/p>\n5<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Use direct str variable to replace as shown below for fixing the issue.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\n# yum list available &gt; \/tmp\/available_pkgs.txt<br \/>\n# cat \/tmp\/available_pkgs.txt\u00a0 |egrep python3<br \/>\n# yum -y install python36u<br \/>\n# python3.6 &#8211;version<br \/>\n# yum -y install python36u-pip<br \/>\n# yum -y install python36u-devel<br \/>\n# python3.6 -V<br \/>\n# mkdir ~\/environments<br \/>\n# cd ~\/environments\/<br \/>\n# python3.6 -m venv my_env<br \/>\n# source ~\/environments\/my_env\/bin\/activate<br \/>\n# python -V[\/crayon]<\/p>\n6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>19. Problem(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\n# yum list available &gt; \/tmp\/available_pkgs.txt<br \/>\n# cat \/tmp\/available_pkgs.txt\u00a0 |egrep python3<br \/>\n# yum -y install python36u<br \/>\n# python3.6 &#8211;version<br \/>\n# yum -y install python36u-pip<br \/>\n# yum -y install python36u-devel<br \/>\n# python3.6 -V<br \/>\n# mkdir ~\/environments<br \/>\n# cd ~\/environments\/<br \/>\n# python3.6 -m venv my_env<br \/>\n# source ~\/environments\/my_env\/bin\/activate<br \/>\n# python -V[\/crayon]<\/p>\n7<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Use str or int function appropriately.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\n# yum list available &gt; \/tmp\/available_pkgs.txt<br \/>\n# cat \/tmp\/available_pkgs.txt\u00a0 |egrep python3<br \/>\n# yum -y install python36u<br \/>\n# python3.6 &#8211;version<br \/>\n# yum -y install python36u-pip<br \/>\n# yum -y install python36u-devel<br \/>\n# python3.6 -V<br \/>\n# mkdir ~\/environments<br \/>\n# cd ~\/environments\/<br \/>\n# python3.6 -m venv my_env<br \/>\n# source ~\/environments\/my_env\/bin\/activate<br \/>\n# python -V[\/crayon]<\/p>\n8<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>20. Problem(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>NameError: name &#8216;cmp&#8217; is not defined<\/span><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Use deepdiff module and DeepDiff class to do object comparison.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">21. Problem(s):<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# yum -y install https:\/\/centos7.iuscommunity.org\/ius-release.rpm<br \/>\n# yum list available &gt; \/tmp\/available_pkgs.txt<br \/>\n# cat \/tmp\/available_pkgs.txt\u00a0 |egrep python3<br \/>\n# yum -y install python36u<br \/>\n# python3.6 &#8211;version<br \/>\n# yum -y install python36u-pip<br \/>\n# yum -y install python36u-devel<br \/>\n# python3.6 -V<br \/>\n# mkdir ~\/environments<br \/>\n# cd ~\/environments\/<br \/>\n# python3.6 -m venv my_env<br \/>\n# source ~\/environments\/my_env\/bin\/activate<br \/>\n# python -V[\/crayon]<\/p>\n9<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span>Solution(s): <\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# pip3.6 install requests<br \/>\n# pip3.6 install sgmllib3k<br \/>\n# pip3.6 install paramiko<br \/>\n# pip3.6 install httplib2<br \/>\n# pip3.6 install pyyaml<br \/>\n# pip3.6 install pytz<br \/>\n# pip3.6 install Geohash<br \/>\n# pip3.6 install python-geohash<br \/>\n# pip3.6 install deepdiff<br \/>\n# pip3.6 install pyes[\/crayon]<\/p>\n0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span>Convert str to int as below for the above type error issue.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p>[crayon lang=&#8221;sh&#8221; decode=&#8221;true&#8221;]# pip3.6 install requests<br \/>\n# pip3.6 install sgmllib3k<br \/>\n# pip3.6 install paramiko<br \/>\n# pip3.6 install httplib2<br \/>\n# pip3.6 install pyyaml<br \/>\n# pip3.6 install pytz<br \/>\n# pip3.6 install Geohash<br \/>\n# pip3.6 install python-geohash<br \/>\n# pip3.6 install deepdiff<br \/>\n# pip3.6 install pyes[\/crayon]<\/p>\n1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8212;-<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s all for now on the list of problems to watch for when you upgrade Python version 2 to Python version 3. We will post more learnings in future blog posts. In the meantime, good luck migrating!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span>Further readings<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The following references were helped us. You can also read further at below reference links to get more details and improve your code porting to Python 3.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.python.org\/dev\/peps\/pep-0373\/\"><span>https:\/\/www.python.org\/dev\/peps\/pep-0373\/<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/wiki.python.org\/moin\/Python2orPython3\"><span>https:\/\/wiki.python.org\/moin\/Python2orPython3<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.toptal.com\/python\/python-3-is-it-worth-the-switch\"><span>https:\/\/www.toptal.com\/python\/python-3-is-it-worth-the-switch<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/weknowinc.com\/blog\/running-multiple-python-versions-mac-osx\"><span>https:\/\/weknowinc.com\/blog\/running-multiple-python-versions-mac-osx<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/docs.python.org\/3\/howto\/pyporting.html\"><span>https:\/\/docs.python.org\/3\/howto\/pyporting.html<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/wsvincent.com\/install-python3-mac\/\"><span>https:\/\/wsvincent.com\/install-python3-mac\/<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/python3porting.com\/pdfs\/SupportingPython3-screen-1.0-latest.pdf\"><span>https:\/\/python3porting.com\/pdfs\/SupportingPython3-screen-1.0-latest.pdf<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/riptutorial.com\/Download\/python-language.pdf\"><span>https:\/\/riptutorial.com\/Download\/python-language.pdf<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/docs.couchbase.com\/python-sdk\/2.5\/start-using-sdk.html\"><span>https:\/\/docs.couchbase.com\/python-sdk\/2.5\/start-using-sdk.html<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/docs.couchbase.com\/c-sdk\/2.10\/start-using-sdk.html\"><span>https:\/\/docs.couchbase.com\/c-sdk\/2.10\/start-using-sdk.html<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/pypi.org\/project\/deepdiff\/\"><span>https:\/\/pypi.org\/project\/deepdiff\/<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/buildmedia.readthedocs.org\/media\/pdf\/portingguide\/latest\/portingguide.pdf\"><span>https:\/\/buildmedia.readthedocs.org\/media\/pdf\/portingguide\/latest\/portingguide.pdf<\/span><\/a><\/li>\n\n\n<li><a href=\"https:\/\/ptgmedia.pearsoncmg.com\/imprint_downloads\/informit\/promotions\/python\/python2python3.pdf\"><span>https:\/\/ptgmedia.pearsoncmg.com\/imprint_downloads\/informit\/promotions\/python\/python2python3.pdf<\/span><\/a><\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Hope you had a good time reading!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Disclaimer:<\/strong> Please view this as a quick reference for your Python 3 upgrade, rather than a complete guide to resolving porting issues. Our intent here is to help you at some level and give you a jump start on the porting process. Please feel free to share if you learned something new that can help us. Your positive feedback is appreciated!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8212;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks to Raju Suravarjjala and Keshav Murthy for their key inputs and feedback.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction The last major Python upgrade &#8212; to version 3 &#8212; arrived in Dec. 2008, nearly 12 years ago. And yet there is a good chance that you are still working on the Python 2 product or test code. If so, then you may be\u00a0 seeing the below deprecation message as a reminder to update [&hellip;]<\/p>\n","protected":false},"author":46261,"featured_media":1588,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"_acf":"","footnotes":""},"categories":[136,355,54,381,353],"tags":[6],"ppma_author":[382],"class_list":["post-1589","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices-and-tutorials","category-community","category-couchbase-server","category-python","category-solutions","tag-nosql-database"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.6 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python 2 to 3 Migration: How to Update &amp; Key Differences<\/title>\n<meta name=\"description\" content=\"Learn how to update from Python 2 to 3 in this post from Couchbase. We also cover their key differences and identify common problems with migration.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/es\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/\" \/>\n<meta property=\"og:locale\" content=\"es_MX\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Update Python 2 to Python 3 &amp; The Differences Between Them\" \/>\n<meta property=\"og:description\" content=\"Learn how to update from Python 2 to 3 in this post from Couchbase. We also cover their key differences and identify common problems with migration.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/es\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-10-13T21:34:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/5\/2026\/05\/update-python-blogbanner.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1575\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jagadesh Munta, Principal Software Engineer, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jagadesh Munta, Principal Software Engineer, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/\"},\"author\":{\"name\":\"Jagadesh Munta, Principal Software Engineer, Couchbase\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/person\\\/5efab7fca2a650b389d487e721997306\"},\"headline\":\"How to Update Python 2 to Python 3 &amp; The Differences Between Them\",\"datePublished\":\"2019-10-13T21:34:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/\"},\"wordCount\":4509,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2026\\\/05\\\/update-python-blogbanner.jpg\",\"keywords\":[\"NoSQL Database\"],\"articleSection\":[\"Best Practices and Tutorials\",\"Community\",\"Couchbase Server\",\"Python\",\"Solutions\"],\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/\",\"name\":\"Python 2 to 3 Migration: How to Update & Key Differences\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2026\\\/05\\\/update-python-blogbanner.jpg\",\"datePublished\":\"2019-10-13T21:34:34+00:00\",\"description\":\"Learn how to update from Python 2 to 3 in this post from Couchbase. We also cover their key differences and identify common problems with migration.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2026\\\/05\\\/update-python-blogbanner.jpg\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2026\\\/05\\\/update-python-blogbanner.jpg\",\"width\":1575,\"height\":628},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/ko\\\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Update Python 2 to Python 3 &amp; The Differences Between Them\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2026\\\/06\\\/logo.svg\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/5\\\/2026\\\/06\\\/logo.svg\",\"width\":\"1024\",\"height\":\"1024\",\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/person\\\/5efab7fca2a650b389d487e721997306\",\"name\":\"Jagadesh Munta, Principal Software Engineer, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6d1189147482e8a4e1c0d2a3db919014c2cfe816b6d11357c3fd740f9deadd31?s=96&d=mm&r=g2b547f1e03e58f24f78d6318913302d1\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6d1189147482e8a4e1c0d2a3db919014c2cfe816b6d11357c3fd740f9deadd31?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6d1189147482e8a4e1c0d2a3db919014c2cfe816b6d11357c3fd740f9deadd31?s=96&d=mm&r=g\",\"caption\":\"Jagadesh Munta, Principal Software Engineer, Couchbase\"},\"description\":\"Jagadesh Munta is a Principal Software Engineer at Couchbase Inc. USA. Prior to this, he was a veteran in Sun Microsystems and Oracle together for 19 years. Jagadesh is holding Masters in Software Engineering at San Jose State University,USA and B.Tech. Computer Science and Engineering at JNTU,India. He is an author of \\\"Software Quality and Java Automation Engineer Survival Guide\u201d to help Software developers and Quality automation engineers.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/es\\\/author\\\/jagadesh\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python 2 to 3 Migration: How to Update & Key Differences","description":"Learn how to update from Python 2 to 3 in this post from Couchbase. We also cover their key differences and identify common problems with migration.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/es\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/","og_locale":"es_MX","og_type":"article","og_title":"How to Update Python 2 to Python 3 &amp; The Differences Between Them","og_description":"Learn how to update from Python 2 to 3 in this post from Couchbase. We also cover their key differences and identify common problems with migration.","og_url":"https:\/\/www.couchbase.com\/blog\/es\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/","og_site_name":"The Couchbase Blog","article_published_time":"2019-10-13T21:34:34+00:00","og_image":[{"width":1575,"height":628,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/5\/2026\/05\/update-python-blogbanner.jpg","type":"image\/jpeg"}],"author":"Jagadesh Munta, Principal Software Engineer, Couchbase","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jagadesh Munta, Principal Software Engineer, Couchbase","Est. reading time":"11 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/"},"author":{"name":"Jagadesh Munta, Principal Software Engineer, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5efab7fca2a650b389d487e721997306"},"headline":"How to Update Python 2 to Python 3 &amp; The Differences Between Them","datePublished":"2019-10-13T21:34:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/"},"wordCount":4509,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/5\/2026\/05\/update-python-blogbanner.jpg","keywords":["NoSQL Database"],"articleSection":["Best Practices and Tutorials","Community","Couchbase Server","Python","Solutions"],"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/","url":"https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/","name":"Python 2 to 3 Migration: How to Update & Key Differences","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/5\/2026\/05\/update-python-blogbanner.jpg","datePublished":"2019-10-13T21:34:34+00:00","description":"Learn how to update from Python 2 to 3 in this post from Couchbase. We also cover their key differences and identify common problems with migration.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/5\/2026\/05\/update-python-blogbanner.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/5\/2026\/05\/update-python-blogbanner.jpg","width":1575,"height":628},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/ko\/tips-and-tricks-for-upgrading-from-python-2-to-python-3\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Update Python 2 to Python 3 &amp; The Differences Between Them"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/5\/2026\/06\/logo.svg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/5\/2026\/06\/logo.svg","width":"1024","height":"1024","caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5efab7fca2a650b389d487e721997306","name":"Jagadesh Munta, Principal Software Engineer, Couchbase","image":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/secure.gravatar.com\/avatar\/6d1189147482e8a4e1c0d2a3db919014c2cfe816b6d11357c3fd740f9deadd31?s=96&d=mm&r=g2b547f1e03e58f24f78d6318913302d1","url":"https:\/\/secure.gravatar.com\/avatar\/6d1189147482e8a4e1c0d2a3db919014c2cfe816b6d11357c3fd740f9deadd31?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6d1189147482e8a4e1c0d2a3db919014c2cfe816b6d11357c3fd740f9deadd31?s=96&d=mm&r=g","caption":"Jagadesh Munta, Principal Software Engineer, Couchbase"},"description":"Jagadesh Munta is a Principal Software Engineer at Couchbase Inc. USA. Prior to this, he was a veteran in Sun Microsystems and Oracle together for 19 years. Jagadesh is holding Masters in Software Engineering at San Jose State University,USA and B.Tech. Computer Science and Engineering at JNTU,India. He is an author of \"Software Quality and Java Automation Engineer Survival Guide\u201d to help Software developers and Quality automation engineers.","url":"https:\/\/www.couchbase.com\/blog\/es\/author\/jagadesh\/"}]}},"acf":[],"authors":[{"term_id":382,"user_id":46261,"is_guest":0,"slug":"jagadesh","display_name":"Jagadesh Munta, Principal Software Engineer, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","author_category":"","first_name":"Jagadesh","last_name":"Munta, Principal Software Engineer, Couchbase","user_url":"","job_title":"","description":"Jagadesh Munta is a Principal Software Engineer at Couchbase Inc. USA. Prior to this, he was a veteran in Sun Microsystems and Oracle together for 19 years. Jagadesh is holding Masters in Software Engineering at San Jose State University,USA and B.Tech. Computer Science and Engineering at JNTU,India. He is an author of \"Software Quality and Java Automation Engineer Survival Guide\u201d to help Software developers and Quality automation engineers."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/posts\/1589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/users\/46261"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/comments?post=1589"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/posts\/1589\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/media\/1588"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/media?parent=1589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/categories?post=1589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/tags?post=1589"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/es\/wp-json\/wp\/v2\/ppma_author?post=1589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}