<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Python on Vincent Frimpong</title>
    <link>https://blog.aduuna.dev/tags/python/</link>
    <description>Recent content in Python on Vincent Frimpong</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Thu, 04 Oct 2018 17:18:20 +0000</lastBuildDate>
    <atom:link href="https://blog.aduuna.dev/tags/python/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Let&#39;s take it online — Deploying your flask Application to PythonAnywhere</title>
      <link>https://blog.aduuna.dev/lets-take-it-online-deploying-your-flask-application-to-pythonanywhere/</link>
      <pubDate>Thu, 04 Oct 2018 17:18:20 +0000</pubDate>
      <guid>https://blog.aduuna.dev/lets-take-it-online-deploying-your-flask-application-to-pythonanywhere/</guid>
      <description>In this tutorial, we will take a simple flask app from our local machine to a server online. I assume it is your first time doing this and I try to explain...</description>
      <content:encoded><![CDATA[<p>In this tutorial, we will take <a href="https://github.com/puclubug/simple_flask_app">a simple flask</a> app from our local machine to a server online. I assume it is your first time doing this and I try to explain everything to the most basic level. Sorry to the Ninjas</p>
<h3 id="boring-talk">Boring Talk</h3>
<p>You can scroll to the tutorial Section if it gets boring here.</p>
<p><strong>So what the hell is a server?</strong></p>
<p>Let’s make it practical since we&rsquo;ve all used the internet before. When you visit a website to look for information, basically, you are a client on the internet and someone needs to serve you with that information. It is like this:</p>
<ul>
<li>Internet —Restaurants</li>
<li>You the client— Customer</li>
<li>Server — Waiter/Server</li>
<li>request for webPage — Order for food</li>
</ul>
<p>So when we build web apps with Flask, Django, or Pyramid, we are designing what and how to serve our customers so that a computer can serve our clients for us.</p>
<p><strong>Okay, so How Do I Serve?</strong></p>
<p>From what is said above we can tell that a server is just another computer. A computer that does one thing — Serve. Any computer could be a Server. I once used my raspberry pi as a staging server. When you are developing with Django or Flask, you have a development server running on your local machine.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">$ python -m SimpleHTTPServer 8000
</span></span></code></pre></div><p>This command starts a server at port 8000 in the directory it was run from.</p>
<p>But we need a constant power supply, A stable internet connection with a reasonable speed, and sometimes an ample storage space to keep our Restaurant open at all times. That is why we need the services of Server Companies to help us stay online.</p>
<h3 id="tutorial">Tutorial</h3>
<p>We have several options available to us because its 2018 and cloud computing is the hot cake for conglomerates. We will use PaaS/IaaS(Platform as a Service/Infrastructure as a Service) for our hosting because we get to skip operating system configurations, server setup, and focus on deploying fast. Plus it’s cheaper and mostly free. We have Google App Engine, Amazon Web Services, Heroku, and pythonanywhere as our favorite options today. <a href="https://blog.appdynamics.com/product/battle-of-the-paas-python-apps-in-the-cloud/">click here</a> if you want to read more about PaaS/IaaS.</p>
<h3 id="part-1-deploying-to-pythonanywhere">Part 1: Deploying to PythonAnywhere.</h3>
<p>For simplicity, let us all clone this simple app. and see it run locally. Use this only if you don’t have a working flask app but you want to follow the tutorial</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">$ git clone https://github.com/puclubug/simple_flask_app.git
</span></span><span class="line"><span class="cl">$ cd simple_flask_app
</span></span><span class="line"><span class="cl">$ git remote rm origin
</span></span><span class="line"><span class="cl">$ python main.py
</span></span></code></pre></div><p>You can visit <a href="http://localhost:8000/">http://localhost:8000/</a> in your browser to see it run and use CTRL+C to quit the server when done. If you don&rsquo;t have git installed, take a minute to get it <a href="http://git-scm.com">here</a>.</p>
<p>But If you have built your flask app locally on your machine, then in your app’s directory run this in your bash over there</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">echo &#34;# simple_flask_app&#34; &gt;&gt; README.md
</span></span><span class="line"><span class="cl">git init
</span></span><span class="line"><span class="cl">git add README.md
</span></span><span class="line"><span class="cl">git commit -m &#34;first commit&#34;
</span></span></code></pre></div><p><strong>Steps</strong></p>
<ol>
<li>Create accounts on <a href="http://github.com/join">GitHub</a> and <a href="https://www.pythonanywhere.com/ahl/">PythonAnywhere</a> if you haven&rsquo;t done that already and confirm your accounts in your email.</li>
<li>Go to your GitHub account and Add a new repository on GitHub — name it “simple_flask_app”. Leave everything as it is, only enter the name and click on create repository</li>
<li>In your flask app directory, open command prompt and run this but replace my github username — aduuna with yours</li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">git remote add origin https://github.com/aduuna/simple_flask_app.git
</span></span><span class="line"><span class="cl">git push -u origin master
</span></span></code></pre></div><ol start="4">
<li>Let’s create a requirements.txt file, it contains a list of all the installed libraries needed for new python environments to run our code.</li>
</ol>
<p>New File: requirements.txt</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">Click==7.0
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">Flask==1.0.2
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">itsdangerous==0.24
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">Jinja2==2.10
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">MarkupSafe==1.0
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">Werkzeug==0.14.1
</span></span></code></pre></div><p>Those running this in a contained virtual environment can run</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">$ pip freeze &gt; requirements.txt
</span></span></code></pre></div><p>to get it automatically created.</p>
<ol start="5">
<li>Now let’s commit our changes</li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">$ git add .
</span></span><span class="line"><span class="cl">$ git commit -m &#34;Added requirements.txt&#34;
</span></span><span class="line"><span class="cl">$ git push origin master
</span></span></code></pre></div><ol start="6">
<li>Head over to your dashboard on pythonanywhere and click on the blue “$ bash” button to start a bash console on the remote computer pythonanywhere just gave you when you created an account. Treat it just like you treat your bash on your local machine. let us clone our source code onto our new machine:</li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">$ git clone https://github.com/aduuna/simple_flask_app
</span></span></code></pre></div><p>Once again Don’t forget to change my username(aduuna) to yours.</p>
<ol start="7">
<li>click the web tab to add a new web app</li>
</ol>
<p><img alt="In the web Tab, add a new web\u00a0app" loading="lazy" src="https://blog.aduuna.dev/lets-take-it-online-deploying-your-flask-application-to-pythonanywhere/image-01.png"></p>
<p><em>In the web Tab, add a new web app</em></p>
<ul>
<li>Click Next</li>
<li>click Flask then Python3.6</li>
<li>change the path name to “/home/kingkunta/simple_flask_app/main.py”</li>
<li>click Next to complete</li>
</ul>
<ol start="7">
<li>Setup on pythonanywhere is as easy as:</li>
</ol>
<p>on your online console run</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-fallback" data-lang="fallback"><span class="line"><span class="cl">$ cd simple_flask_app
</span></span><span class="line"><span class="cl">$ mkvirtualenv --python=/usr/bin/python3.6 my-virtualenv
</span></span><span class="line"><span class="cl">$ workon my-virtualenv
</span></span><span class="line"><span class="cl">$ pip install --user -r requirements.txt
</span></span><span class="line"><span class="cl">$ git checkout main.py
</span></span></code></pre></div><ol start="8">
<li>We are done. Reload Website in the web Tab. And view your website online at <a href="https://kingkunta.pythonanywhere.com">https://kingkunta.pythonanywhere.com</a>.</li>
</ol>
<blockquote>
<p>Note: yours will be at <a href="https://your_username.pythonanywhere.com">https://your_username.pythonanywhere.com</a></p>
</blockquote>
<blockquote>
<p>All variables used here like “simple_flask_app”, “my-virtualenv” can of course be replaced by anything of your choice, just keep it simple.</p>
</blockquote>
<h2 id="summary">Summary</h2>
<p>All that we did was to upload our code from our desktop to github and then we download the same code to our computer at pythonanywhere and boom, we had our app online.</p>
<p>I will be back with <strong>Part 2</strong> where we use Heroku to host our webapp, I hope you enjoyed it. If you have any questions, corrections or additions you can send me a quick <a href="mailto:tossia13@gmail.com">email here</a> or leave a <a href="https://wa.me/233264236474">whatsapp message</a></p>
]]></content:encoded>
    </item>
    <item>
      <title>Programming is a journey, Start Today.</title>
      <link>https://blog.aduuna.dev/programming-is-a-journey-start-today/</link>
      <pubDate>Wed, 26 Sep 2018 22:01:05 +0000</pubDate>
      <guid>https://blog.aduuna.dev/programming-is-a-journey-start-today/</guid>
      <description>I have been asked several times by new members of PyClub, “How do I start?”</description>
      <content:encoded><![CDATA[<p>I have been asked several times by new members of PyClub, “How do I start?”</p>
<p>I think maybe sharing my experience would help.</p>
<p>When I was starting out I had nothing but an interest to code. The idea of being able to tell a computer what to do felt like a superpower and I just wanted to have that power.</p>
<p>I was excited about being able to create apps, write automating scripts, build websites, hack websites or mobile devices, or do complex calculations that my 991esPlus calculator can’t do. I just wanted to have that geek ability and it was my drive.</p>
<p>I went online and did a search for “best free python3 introductory books” - and I found a pdf book, &ldquo;Coder’s Apprentice&rdquo; by Peter Spronck</p>
<p>Over the next 6 months, from September 2016 to Feb 2017, I read the book from cover to cover. I could have finished way earlier but I was in my first year at University, I had to study my math courses first.</p>
<p>By the time the 2nd sem started, I already knew enough python to skip the entire CSCD102 course because it was an “Introduction to programming with python” course. Please don’t do this because I didn’t, go there and show the world what you know rather you will learn more by sharing and crashing your code occasionally.</p>
<p>So I had a very firm introduction to python, and I was solving basically every problem with python. In counting problems, when I needed to confirm combinations and permutations with actual simulation I wrote a python script. When I was feeling lazy dealing with logic gates and truth tables, I just wrote code to do it for me. In everyday life, I could spend 10min to write a script that will search through multiple books for a string because coding was just fun.</p>
<p>Now what? That was the question on my mind at that time, my options were enormous, thanks to the articles I read online. I realized I could create games, build Android apps, webapps, do data visualization (graphs and charts) all with this python I knew. Yes, there are more uses, but the aforementioned are the ones I remember trying my hands on. I built a game with pygame, did loads of data visualization(matplotlib and seaborn). Before I tried my hands on Web Development, I tried Kivy Android app development, which was very fun although I never deployed my Android app. All these were from my second book in Python — “Python Crash Course” by Eric Matthes. Except for Kivy - which I found by accident.</p>
<p>At the moment, my reference manuals are:</p>
<ul>
<li>“Two scoops of Django” by Daniel Greenfeld,</li>
<li>“Automate the boring stuff” by Al Sweigart,</li>
<li>And the official python reference and Django reference manuals.</li>
</ul>
<p>I’ve been using Django for close to a year now and I feel comfortable here. Although I’m also interested in Machine Learning and General Scientific programming like Numerical Analysis and Data Analysis, I consider myself a novice in that field, and an intermediate in Web Technologies. I have built a couple of webapps using Django and Flask. Most of them, built for fun, and a few of them for clients as a freelancer.</p>
<p>Currently, I have a coaching role with Global Code(A UK organization) and a volunteer coach at Djangogirls. I’m in my third year in the University and the lead of PyClub UG. So it hasn’t been a bad journey if you asked me.</p>
<p>The bottom line is that you should get something to drive you, share as you learn, stay focused on something you want to do but don’t be afraid to try out interesting technologies when you pick up little projects along the way.</p>
<p>This may not be your exact journey in learning programming with python. Others may like to watch videos rather than read books. Or perhaps take an online course which combines both text and video materials. In that case, <a href="http://cousera.org/learn/python">this one on coursera</a> would be a great start but there are similar or perhaps better ones out there on <a href="http://udemy.com">udemy</a>, <a href="http://pythonanywhere.com">pythonanywhere</a>, and <a href="http://datacamp.com">datacamp</a>.</p>
<p>Here is a link to download all the books mentioned in this article: <a href="https://bit.ly/start-coding-python">https://bit.ly/start-coding-python</a></p>
<blockquote>
<p>Remember, The only way to learn how to code is to code — Anonymous</p>
</blockquote>
<p><img alt="Join Us and Network with beginners and pro’s who use\u00a0python" loading="lazy" src="https://blog.aduuna.dev/programming-is-a-journey-start-today/image-01.jpeg"></p>
<p><em>Join Us and Network with beginners and pro’s who use python</em></p>
]]></content:encoded>
    </item>
  </channel>
</rss>
