{"id":8678,"date":"2015-02-12T15:49:01","date_gmt":"2015-02-12T15:49:01","guid":{"rendered":"https:\/\/wp.okra.host\/article\/changing-python-versions\/"},"modified":"2021-03-07T14:44:25","modified_gmt":"2021-03-07T13:44:25","slug":"changing-python-versions","status":"publish","type":"ht_kb","link":"https:\/\/kb.okra.host\/de\/article\/changing-python-versions\/","title":{"rendered":"\u00c4ndern von Python-Versionen"},"content":{"rendered":"<h3 id=\"overview\" ><del><\/del>Overview<\/h3>\n<p>Recent platforms (<a title=\"Determining platform version\" href=\"https:\/\/kb.okra.host\/platform\/determining-platform-version\/\">v6+<\/a>) support multiple Python interpreters from the shell using <a href=\"https:\/\/github.com\/yyuu\/pyenv\">pyenv<\/a>. pyenv allows seamless switching between available Python versions, and manages version-specific\u00a0<a title=\"Installing packages\" href=\"https:\/\/kb.okra.host\/python\/installing-packages\/\">package installations<\/a>\u00a0too.<\/p>\n<h2 id=\"basics\" >Basics<\/h2>\n<p>All commands are done from the <a title=\"Accessing terminal\" href=\"https:\/\/kb.okra.host\/terminal\/accessing-terminal\/\">terminal<\/a>.<\/p>\n<h3 id=\"listing-versions\" >Listing versions<\/h3>\n<p>To get a current list of available Python interpreters, use <code>pyenv versions<\/code>:<\/p>\n<figure class=\"pyenv-output\" style=\"width: 400px\">\n<div class=\"terminal\">\n<div class=\"indicators\"><\/div>\n<div class=\"terminal-text\"><code>[myadmin@sol ~]$ pyenv versions<br \/>\nsystem<br \/>\n2.7.8<br \/>\n* 3.3.5 (set by \/home\/myadmin\/.python-version)<br \/>\n3.4.1<\/code><\/div>\n<\/div>\n<\/figure>\n<div class=\"clear\"><\/div>\n<p>Of importance is\u00a0<code>system<\/code>, which is the default system interpreter. Without pyenv installed,\u00a0<code>system<\/code> is the default interpreter used.\u00a0<code>2.7.8<\/code>,\u00a0<code>3.3.5<\/code>, and\u00a0<code>3.4.1<\/code>\u00a0are additional interpreters installed in addition to the system version under <code>\/.socket\/python\/versions<\/code>.<\/p>\n<h3 id=\"selecting-a-version\" >Selecting\u00a0a version<\/h3>\n<p>A version may be\u00a0defined per-directory and inherited recursively within all child directories. Versions are defined for a directory, and its child directories, by <code>pyenv local<\/code>:<\/p>\n<figure class=\"pyenv-output\" style=\"width: 400px\">\n<div class=\"terminal\">\n<div class=\"indicators\"><\/div>\n<div class=\"terminal-text\"><code>[myadmin@sol ~]$ pyenv version<br \/>\n3.3.5 (set by \/home\/myadmin\/.python-version)<br \/>\n[myadmin@sol ~]$ cd \/var\/www\/<br \/>\n[myadmin@sol www]$ pyenv local system<br \/>\n[myadmin@sol www]$ pyenv version<br \/>\nsystem (set by \/var\/www\/.python-version)<br \/>\n[myadmin@sol www]$ cd ~\/test<br \/>\n[myadmin@sol ~\/test]$ pyenv version<br \/>\n3.3.5 (set by \/home\/myadmin\/.python-version)<\/code><\/div>\n<\/div>\n<\/figure>\n<div class=\"clear\"><\/div>\n<p>Two versions of Python are defined, one in <code>\/home\/myadmin<\/code> and another in <code>\/var\/www<\/code>. Versions are controlled by a file called <code>.python-version<\/code>\u00a0and pyenv will ascend each parent directory until it reaches root (<code>\/<\/code>) or <code>.python-version<\/code>\u00a0is found. If no control file is found, the current Python interpreter will be used.<\/p>\n<p>You can then delegate a single Python version to handle a collection of projects by locating projects under an additional directory and defining a Python version in its parent directory:<\/p>\n<pre>www       &lt;-- NO .python-version\r\n|-- proj3 &lt;-- .python-version (3.3.5)\r\n| |-- mydjango  (3.3.5)\r\n| `-- flask     (3.3.5)\r\n`-- proj2 &lt;-- .python-version (2.7.5)\r\n  |-- newdjango (2.7.5)\r\n  `-- mezzanine (2.7.5)<\/pre>\n<p>Control files are located under <code>\/var\/www\/proj3<\/code> and <code>\/var\/www\/proj2<\/code> allowing projects located under these directories to use Python 3 or Python 2 respectively.<\/p>\n<h3 id=\"package-locations\" >Package locations<\/h3>\n<p>Packages are installed\u00a0using <a title=\"Installing packages\" href=\"https:\/\/kb.okra.host\/python\/installing-packages\/\">pip<\/a>\u00a0as normal. Packages are located under <code>\/usr\/local\/lib\/python\/<em>&lt;MAJOR&gt;<\/em>.<em>&lt;MINOR&gt;<\/em>.<em>&lt;PATCH&gt;<\/em><\/code> using <a href=\"http:\/\/www.semver.org\">semantic versioning<\/a>\u00a0to avoid conflict. Any binaries installed under \/usr\/local\/bin, however, will conflict with each other if those binaries, bundled in different versions of the package, differ. <a href=\"https:\/\/github.com\/yyuu\/pyenv-virtualenv#usage\">pyenv-virtualenv<\/a> +\u00a0<a href=\"https:\/\/virtualenv.pypa.io\/en\/latest\/\">virtualenv<\/a> is recommended to isolate packages of different versions that rely on the same Python interpreter.<\/p>\n<h3 id=\"caveats\" >Caveats<\/h3>\n<h4 id=\"shebangs\" >Shebangs<\/h4>\n<p>Shell or FastCGI scripts typically begin with <code>#!\/usr\/bin\/python<\/code>. This is the system version that will bypass pyenv initialization. Change this line to <code>#!\/usr\/bin\/env python<\/code> to use python found in the shell path.<\/p>\n<h2 id=\"see-also\" >See also<\/h2>\n<ul>\n<li><a href=\"https:\/\/github.com\/yyuu\/pyenv\">pyenv<\/a> github<\/li>\n<li><a href=\"https:\/\/virtualenv.pypa.io\/en\/latest\/\">virtualenv<\/a> (manage same Python version, different package versions)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Overview Recent platforms (v6+) support multiple Python interpreters from the shell using pyenv. pyenv allows seamless switching between available Python versions, and manages version-specific\u00a0package installations\u00a0too. Basics All commands are done from the terminal. Listing versions To get a current list of available Python interpreters, use pyenv versions: [myadmin@sol ~]$ pyenv&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[65],"ht-kb-tag":[],"class_list":["post-8678","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-python"],"_links":{"self":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/comments?post=8678"}],"version-history":[{"count":1,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8678\/revisions"}],"predecessor-version":[{"id":8679,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8678\/revisions\/8679"}],"wp:attachment":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/media?parent=8678"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb-category?post=8678"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb-tag?post=8678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}