Saturday, December 16, 2017

'_remove_dead_weakref' error after upgrading to Ubuntu 17.10

Well, after finally getting my Flask app running and returning data, I upgraded my system to Ubuntu 17.10 (from 17.04).  Today, I tried to start my flask app and was greeted with a bunch of Python error output and the following error:

ImportError: cannot import name '_remove_dead_weakref'

I was baffled as the app worked the day before.  So after some digging around the Googles, I found that the issue was caused by my upgrade to 17.10.

The fix....... delete your virtual environment and rebuild it.  I am not saying delete your project directory, I am saying delete your envs directory (which is where the executables for the virtual environment are.  Some people put it in the same directory.  If you are like me, you have a central location where you keep them. 

You will need to remove that entire directory, rebuild it and then re-run the virtualenv command to create the virtualized environment and then install any modules that you had previously installed (as they get stored in the directory structure you just deleted.  After that, your app and its parts should work fine.

Wednesday, December 13, 2017

Starting Out (and pulling my hair out) with Flask

Recently I started learning the Flask web framework.  Mostly because I have been doing a bunch of Python coding and would like that to bleed over a bit into the web development arena.  The need is not really out of anything work-related, its more of a personal project need.

I can say, though, that getting apache and Flask operating together has certainly added a few grey hairs to my head, mostly in frustration.  There are plenty of resources ( if you search the Googles) for setting up Apache web server and Flask, to work together.  But I have to say that, as great as the resources that are out there, are, there are a few (pertinent) details that were left out of most of them that I will now cover.

First, working in a Virtual Environment does not have all of the same settings as not working in one.  If you look at this link, you will see (near the bottom of the document) that there are a couple of things you have to set in your .wsgi file, to specify the load paths for your virtual environment. 
NOTE: It is important to note that that link is the same root site for the Flask link above.  So they definitely have a lot of documentation on their product.

Now, while the above is important, it didn't solve my issue, which is that on a machine remote to where I am running my Flask app and web server, I was not able to go to http://:5000 (the port Flask runs on) and see the page displayed as expected.  Instead I received a typical error page stating that the page could not be loaded.  This got even more frustrating with each new thing that I tried or modified to get it working.  No matter how seemingly possible of a fix, it didn't work.  Until.....

I found a StackOverflow thread about running a Flask app under the Apache web server.  I read the person's question and went through their code (seeing all the similarities) and there it was... a setting that no other site had mentioned.  Not even the video tutorial I was going through.  It was part of my Flask app's __init__.py file and the part in question looks like this:
app.debug = True
app.run(host='0.0.0.0')
The first line is inconsequential and just turns on debug mode.  The second line was 1/2 different from mine, but crucially different.  I had the app.run() that all the tutorial's had mentioned, but I did not have the host='0.0.0.0' portion.  I put it in, started up Flask (by running the __init__.py file) and VOILA!!!  I had the output that I expected to see in my browser. 

Needless to say, it was certainly a learning experience ( as I now have plenty of notes for running a Flask app with Apache).  Now I can get on with my learning of the Framework since the tedious job of getting the web page serving is now out of the way.  Yay!



Wednesday, March 01, 2017

I give you.... PyBlueprint

About 3 years ago (or so), I created a bash script for starting a new Python project.  I was tired of setting up each new project by hand and wanted a quicker way to do it as a time saver.   That endeavor yielded a script that I have used for the last 3 years.

While the script works fine from a bash perspective, I was not yet happy with it in that state.  So, I embarked on re-writing it in Python.  I didn't get the chance to work full force on it right away, but over the last week or so, I have made an immense amount of progress on it.  So much, that I am ready to announce the project for people to download, play with and hopefully enjoy.

Overview:

PyBlueprint's whole purpose is to create a base project directory for new Python projects.  Some of the features that the script has are:

    - Creates project directory for you and populates it with a base set of files (script, README, etc)
    - Initializes a new git repo (or not, if that is your choice)
    - Create a new Github or Bitbucket repository for you to push your code to

I could be over estimating, but I would say that this project saves me about 5-10 minutes of initial project setup so that I can get to coding my projects quicker.

I know that not everyone works in the same manner and we each have our own requirements.  I just ask that if you are a python developer, please give this a shot and see if it works for you.  If there are suggestions, I am open to them, please just open an issue in the project.

Project Link:  https://bitbucket.org/numberwhun/pyblueprint

UPDATE: I realized a short time ago that I still had the repository set to be private.  I have changed it to be a public repo.  Sorry about that!
 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.