{"id":223,"date":"2018-04-20T00:38:26","date_gmt":"2018-04-20T07:38:26","guid":{"rendered":"https:\/\/www.falatic.com\/?p=223"},"modified":"2018-04-20T00:38:26","modified_gmt":"2018-04-20T07:38:26","slug":"migrate-to-python-3","status":"publish","type":"post","link":"https:\/\/www.falatic.com\/index.php\/223\/migrate-to-python-3","title":{"rendered":"Migrate to Python 3!"},"content":{"rendered":"<p><a href=\"https:\/\/www.falatic.com\/wp-content\/uploads\/2018\/04\/python-logo-master-v3-TM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-224\" src=\"https:\/\/www.falatic.com\/wp-content\/uploads\/2018\/04\/python-logo-master-v3-TM.png\" alt=\"Python logo\" width=\"601\" height=\"203\" data-wp-pid=\"224\" srcset=\"https:\/\/www.falatic.com\/wp-content\/uploads\/2018\/04\/python-logo-master-v3-TM.png 601w, https:\/\/www.falatic.com\/wp-content\/uploads\/2018\/04\/python-logo-master-v3-TM-300x101.png 300w, https:\/\/www.falatic.com\/wp-content\/uploads\/2018\/04\/python-logo-master-v3-TM-600x203.png 600w\" sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><\/a><\/p>\n<p>My day job has been keeping me busy, and I haven&#8217;t had a lot of spare time to work on projects or to even read (I&#8217;ve got quite the backlog of reading to catch up on &#8211; particularly <em>New Scientist<\/em> and <em>The Economist<\/em>\u00a0which are staples for my information appetite!)<\/p>\n<p>That said, I&#8217;ve been working on quite a few interesting things, particularly a major migration to Python 3. The <a href=\"https:\/\/pythonclock.org\/\" target=\"_blank\" rel=\"noopener\">clock&#8217;s ticking on Python 2<\/a>\u00a0(EOL at the end of 2019), major packages like Pandas are dropping support for Python 2 at the end of 2018, and minor packages are doing so as well. You can either stay on EOL\/unsupported packages indefinitely, or migrate to Python 3 and leave all that mess behind!<\/p>\n<p>When migrating to Python 3, it helps to have a plan:<\/p>\n<ul>\n<li>Select a target version &#8211; I strongly recommend going straight to Python 3.6 or later as 3.5 goes EOL only a few months after 2.7.<\/li>\n<li>On some platforms you may need to build Python 3.6 (not difficult), or use one from your repository of choice (e.g., the <a href=\"https:\/\/launchpad.net\/~deadsnakes\/+archive\/ubuntu\/ppa\" target=\"_blank\" rel=\"noopener\">Deadsnakes PPA<\/a> for Ubuntu).<\/li>\n<li>Whatever you do, do NOT blindly replace your <em>system<\/em> Python with 3.6! Install 3.6 as a <code>\/usr\/local\/bin<\/code> package and use it from there.<\/li>\n<li>To minimize downtime for an active project, make your existing code cross-compatible as much as possible. <code><a href=\"https:\/\/docs.python.org\/2\/library\/2to3.html\" target=\"_blank\" rel=\"noopener\">2to3<\/a><\/code> is the main tool for simply upgrading code but for cross-version compatibility I prefer <a href=\"http:\/\/python-modernize.readthedocs.io\/\" target=\"_blank\" rel=\"noopener\">Python-Modernize<\/a>, which extends 2to3 so as to leverage <a href=\"http:\/\/six.readthedocs.io\/\" target=\"_blank\" rel=\"noopener\"><code>six<\/code><\/a> to allow cross-version compatibility. The very latest updates in <a href=\"https:\/\/github.com\/python-modernize\/python-modernize\" target=\"_blank\" rel=\"noopener\">its github repo<\/a> enhance its. capabilities. Furthermore, I have <a href=\"https:\/\/github.com\/python-modernize\/python-modernize\/pull\/165\" target=\"_blank\" rel=\"noopener\">a pull request pending<\/a> that fixes something that causes more problems than it solves.<\/li>\n<li>If you&#8217;re using TeamCity, I&#8217;ve written a wrapper for Modernize called <a href=\"https:\/\/pypi.org\/project\/modernize-reporter\/\" target=\"_blank\" rel=\"noopener\">modernize-reporter<\/a> that reports the update details for each file it sees as needing updating back to TeamCity. Much like a linter, this will ensure your updated code stays up to date during the transition period.<\/li>\n<li>Perform testing in parallel with Python 3.6 to flush out any bugs.<\/li>\n<li>Cut over to Python 3.6 in production.<\/li>\n<li>Remove <code>six<\/code>\u00a0and other compatibility fixes &#8211; you won&#8217;t need them now!<\/li>\n<\/ul>\n<p>I&#8217;m fortunate to be able to spearhead this effort where I am, but organizational inertia can be the biggest impediment of all in other places. Staying on Python 2.7 even past EOL is certainly easier and cheaper as it\u00a0 avoids the risk of any downtime or pain points or effort required for an upgrade process.<\/p>\n<p>On the other hand, not upgrading means sliding into <em>The Land of Unsupported Software<\/em> and a security profile that will only get worse over time. That&#8217;s a dead-end, and in this era of cybersecurity and privacy concerns maintaining brittle code on a brittle foundation is bad for business.<\/p>\n<p><strong>So make a plan, make your case, and get moving to Python 3!<\/strong><\/p>\n<!-- wpsso rrssb get buttons: buttons on archive option not enabled -->\n","protected":false},"excerpt":{"rendered":"<p>My day job has been keeping me busy, and I haven&#8217;t had a lot of spare time to work on projects or to even read (I&#8217;ve got quite the backlog <a href=\"https:\/\/www.falatic.com\/index.php\/223\/migrate-to-python-3\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[107,86],"tags":[152,155,153,100,154,120],"class_list":["entry","author-marty","post-223","post","type-post","status-publish","format-standard","category-commentary","category-software-and-hardware-development","tag-2to3","tag-eol","tag-modernize","tag-python","tag-python2","tag-python3"],"_links":{"self":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/comments?post=223"}],"version-history":[{"count":0,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts\/223\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/categories?post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/tags?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}