In the hero python tutorial, virtualenv throws the wsgiref installation (ez_setup syntax error?)

I am reading the Heroku tutorial Getting Started with Python. I'm at the point where I want to create my environment locally with virtualenv so that I can run my test app locally. The requirements.txt file has

wsgiref==0.1.2

      

and after going to this step virutalenv outputs the following error message

Downloading/unpacking wsgiref==0.1.2 (from -r requirements.txt (line 8))
  Downloading wsgiref-0.1.2.zip
  Running setup.py egg_info for package wsgiref
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/private/var/folders/v6/zf84tlbn19zcqlbx977nlrmh0000gn/T/pip_build_jeremy/wsgiref/setup.py", line 5, in <module>
        import ez_setup
      File "./ez_setup/__init__.py", line 170
        print "Setuptools version",version,"or greater has been installed."
                                 ^
    SyntaxError: invalid syntax
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/private/var/folders/v6/zf84tlbn19zcqlbx977nlrmh0000gn/T/pip_build_jeremy/wsgiref/setup.py", line 5, in <module>

    import ez_setup

  File "./ez_setup/__init__.py", line 170

    print "Setuptools version",version,"or greater has been installed."

                             ^

SyntaxError: invalid syntax

      

It's clear to me what's going on: at some point python3.3 (mine by default) is used to install something via a python2.x script. I just don't know how to fix this. My virtualenv only has Python3.x utilities and I'm not sure what ez_setup is, even after reading his hectic PyPI entry .

How can I fix this?

+3


source to share


1 answer


Heroku supports Python versions 2.4.4 through 3.4.1 .

The tutorial you are using is for Python 2.7.8, so your application is not running locally. If you were to attach the application to Heroku, it will work correctly.

Here you have two options, you can install Python 2.7 on your local machine or modify the tutorial to work with Python 3.x

For the first option, using a package manager or other common tool, install Python 2.x. If you are using redhat or another rpm based distribution (like centos, fedora, etc.), be careful not to overwrite your Python system as rpm tools like yum

will stop working.

Once you have Python 2.7.x installed, you will have to install pip and setuptools against this version of Python. Finally, create your virtual environment and then continue learning.



If you want to stick with Python 3.3, you will have to make the following adjustments from the cloned repository:

  • In runtime.txt

    change python-2.7.8

    topython-3.3

  • Change requirements.txt

    to the following:

    django-toolbelt
    
          

You don't need anything else, django-toolbelt

it's just a meta package that will install django, gunicorn, psycopg2, dj-database-url and dj-static.

Create a new virtual environment and then set these requirements.

+7


source







All Articles