{"id":318,"date":"2015-08-18T13:17:44","date_gmt":"2015-08-18T17:17:44","guid":{"rendered":"http:\/\/www.tayloraliss.com\/blog\/?p=318"},"modified":"2015-08-19T18:02:30","modified_gmt":"2015-08-19T22:02:30","slug":"oh-oh-oh-she-moves-she-moves","status":"publish","type":"post","link":"https:\/\/www.tayloraliss.com\/blog\/?p=318","title":{"rendered":"#! #! Oh! Oh! Oh! She Moves! She Moves!"},"content":{"rendered":"<p>In my last post, I mentioned how I was unfamiliar with the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#!<\/code> line found at the beginning of Miguel Grinberg&#8217;s <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">run.py<\/code> script. Here&#8217;s what I have learned:<\/p>\n<p>First, it&#8217;s called a &#8220;shebang&#8221; or &#8220;hash-bang.&#8221;\u00a0I couldn&#8217;t find it on google because google omits special characters. However, I did learn about this awesome search engine that allows them:\u00a0<a href=\"http:\/\/symbolhound.com\/\">http:\/\/symbolhound.com\/<\/a><\/p>\n<p>Shebangs are mainly used on POSIX systems (Linux, Unix, etc.) and don&#8217;t really mean anything on Windows.\u00a0However, Python 3.3 and later <a href=\"http:\/\/stackoverflow.com\/questions\/2429511\/why-do-people-write-usr-bin-env-python-on-the-first-line-of-a-python-script#comment19984261_2429517\">actually come included<\/a> with <strong>Python Launcher for Windows<\/strong> which recognizes the following shebangs\u00a0(which\u00a0<a href=\"http:\/\/stackoverflow.com\/questions\/32064220\/what-is-the-difference-between-these-4-different-types-of-python-shebangs-on-win\">all do the same thing<\/a>):<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-highlight=\"#! \/usr\/bin\/env python #! \/usr\/bin\/python #! \/usr\/local\/bin\/python #! python\" data-enlighter-linenumbers=\"false\">#! \/usr\/bin\/env python\r\n#! \/usr\/bin\/python \r\n#! \/usr\/local\/bin\/python \r\n#! python<\/pre>\n<p>So what do these\u00a0shebangs actually do?<\/p>\n<p>Well, according to <a href=\"https:\/\/www.reddit.com\/r\/learnpython\/comments\/3hdmq5\/what_does_mean\/\">this thread<\/a>,\u00a0they\u00a0tell the OS to search your\u00a0<code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">$PATH<\/code> for an interpreter called <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">python<\/code>, and to run the script using it.<\/p>\n<p>The reason shebangs looks so weird is because they are designed for POSIX systems which have a different directory structure. The\u00a0<code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#! \/usr\/bin\/env python<\/code>\u00a0shebang tells your OS to use the interpreter created in your virtual environment.\u00a0When you <a href=\"http:\/\/blog.miguelgrinberg.com\/post\/the-flask-mega-tutorial-part-i-hello-world\">activate an environment<\/a>:<\/p>\n<blockquote><p>. . . the environment adds the location of its <code>bin<\/code> folder to the system path, so that, for example, when you type\u00a0<code>python<\/code> you get the environment&#8217;s version and not the system&#8217;s one.<\/p><\/blockquote>\n<p>However, according to <a href=\"http:\/\/stackoverflow.com\/a\/13206997\/4298546\">this StackOverflow thread<\/a>:<\/p>\n<blockquote><p>A <code>bin<\/code> directory is created on POSIX systems only . . . Some paths within the virtualenv are slightly different on Windows: scripts and executables on Windows go in <code>env\\Scripts\\<\/code>instead of <code>env\/bin\/<\/code> and libraries go in <code>env\\Lib\\<\/code> rather than\u00a0env<code>\/lib\/<\/code>.<\/p><\/blockquote>\n<p>And finally:<\/p>\n<blockquote><p>In Unix, an <em>executable<\/em> file that&#8217;s meant to be interpreted can indicate what interpreter to use by having a <code>#!<\/code> at the start of the first line, followed by the interpreter (and any flags it may need).<\/p>\n<p>If you&#8217;re talking about other platforms, of course, this rule does not apply (but that &#8220;shebang line&#8221; does no harm, and will help if you ever copy that script to a platform <em>with<\/em> a Unix base, such as Linux, Mac, etc).<\/p>\n<p>. . .<\/p>\n<p>Using <code>env<\/code> gives maximum flexibility in that the user can select the interpreter to use by changing the PATH.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>In my last post, I mentioned how I was unfamiliar with the #! line found at the beginning of Miguel Grinberg&#8217;s run.py script. Here&#8217;s what I have learned: First, it&#8217;s called a &#8220;shebang&#8221; or &#8220;hash-bang.&#8221;\u00a0I couldn&#8217;t find it on google because google omits special characters. However, I did learn about this awesome search engine that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-318","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=318"}],"version-history":[{"count":10,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/318\/revisions"}],"predecessor-version":[{"id":329,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/318\/revisions\/329"}],"wp:attachment":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}