title: NameError: name 'hasattr' is not defined - Python3.6, Django1.11, Ubuntu16-17, Apache2.4, mod_wsgi
body: <p>I've set up my Python/Django virtual environment, and mod_wsgi in daemon mode,  and am pretty sure (done this before) it's "<em>mostly correct</em>" except I get the following error... </p>
  
  <pre><code>[Thu Jul 06 00:35:26.986363 2017] [mpm_event:notice] [pid 11442:tid 140557758930432] AH00493: SIGUSR1 received.  Doing graceful restart
  Exception ignored in: &lt;object repr() failed&gt;
  Traceback (most recent call last):
    File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/PIL/Image.py", line 572, in __del__
  NameError: name 'hasattr' is not defined
  [Thu Jul 06 00:35:27.194483 2017] [mpm_event:notice] [pid 11442:tid 140557758930432] AH00489: Apache/2.4.25 (Ubuntu) mod_wsgi/4.5.15 Python/3.6 configured -- resuming normal operations
  [Thu Jul 06 00:35:27.194561 2017] [core:notice] [pid 11442:tid 140557758930432] AH00094: Command line: '/usr/sbin/apache2'
  </code></pre>
  
  <p>My django app itself is loading fine through wsgi.py but it seems something to do with core python (error with my setup likely) is going wrong as per: <code>NameError: name 'hasattr' is not defined</code></p>
  
  <p>In the browser - I get a plain "Server Error (500)" page and not the standard Apache "Internal Server Error" page.</p>
  
  <p>Leaving out my VirtualHost and steps beyond here are the basic steps I put together for myself if you can spot anything... (I've tried all the different python packages as well not just -venv)</p>
  
  <pre><code>Install Python 3.6 and virtualenv
      sudo apt-get update
      sudo apt-get install python3.6-venv
      sudo apt-get install virtualenv
  (or find the latest and greatest python package that includes pip https://packages.ubuntu.com/ )
  
  
  Install Apache2
      sudo apt-get install apache2 apache2-dev
  
  
  Make and enter a folder for your project - then build a Virtual Environment in it
      mkdir ~/example.com
      cd ~/example.com
      virtualenv --python=/usr/bin/python3.6 py361ve
  
  Enter your new Virtual Environment to install packages to it
      source py361ve/bin/activate
  
  Install Django, mod_wsgi, and any other needed packages
      pip install django
      pip install mod_wsgi
      pip install ...
  (no need for pip3 in virtual environment - django should be the latest release)
  
  
  Run following command and place output in apache config file ( in /etc/apache2/ )
      mod_wsgi-express module-config
  
  
  Exit your virtual environment
      deactivate
  (You can re-enter your virtual environment any time using the source method in step 8)
  </code></pre>
  
  <p>Here's what happens when I stop/start/restart apache2...</p>
  
  <pre><code>apache2 stop...
  
  [Thu Jul 06 06:01:34.190940 2017] [mpm_event:notice] [pid 2015:tid 140157449797120] AH00491: caught SIGTERM, shutting down
  _______________________________________________________________
  apache2 start...
  
  [Thu Jul 06 06:02:39.076741 2017] [mpm_event:notice] [pid 2181:tid 140553545080320] AH00489: Apache/2.4.25 (Ubuntu) mod_wsgi/4.5.15 Python/3.6 configured -- resuming $
  [Thu Jul 06 06:02:39.076890 2017] [core:notice] [pid 2181:tid 140553545080320] AH00094: Command line: '/usr/sbin/apache2'
  _______________________________________________________________
  apache2 restart...
  
  Exception ignored in: &lt;object repr() failed&gt;
  Traceback (most recent call last):
    File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/PIL/Image.py", line 572, in __del__
  NameError: name 'hasattr' is not defined
  [Thu Jul 06 06:05:43.307877 2017] [mpm_event:notice] [pid 2181:tid 140553545080320] AH00491: caught SIGTERM, shutting down
  [Thu Jul 06 06:05:43.492499 2017] [mpm_event:notice] [pid 2301:tid 140353155558912] AH00489: Apache/2.4.25 (Ubuntu) mod_wsgi/4.5.15 Python/3.6 configured -- resuming $
  [Thu Jul 06 06:05:43.492705 2017] [core:notice] [pid 2301:tid 140353155558912] AH00094: Command line: '/usr/sbin/apache2'
  </code></pre>