prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Psycopg2 error after the apk installation.
  ![erro psycopg](https://user-images.githubusercontent.com/39860703/52805033-d8002480-306c-11e9-931b-87bc567e70f0.PNG)
  
  I got this error while debugging the android apk. I associate this to Buildozer because I specified into the buildozer.spec requirements the psycopg2 library. It means that is not working.
  
  How do I fix it? I know that is a recipe for psycopg2 here: https://github.com/kivy/python-for-android/blob/master/pythonforandroid/recipes/psycopg2/__init__.py
  
  How can I add this recipe to my project, to buildozer compile it successfully ?
  
  </issue>
  <code>
  [start of pythonforandroid/recipes/psycopg2/__init__.py]
  1 from pythonforandroid.recipe import PythonRecipe
  2 from pythonforandroid.toolchain import current_directory, shprint
  3 import sh
  4 
  5 
  6 class Psycopg2Recipe(PythonRecipe):
  7     """
  8     Requires `libpq-dev` system dependency e.g. for `pg_config` binary.
  9     """
  10     version = 'latest'
  11     url = 'http://initd.org/psycopg/tarballs/psycopg2-{version}.tar.gz'
  12     depends = ['libpq']
  13     site_packages_name = 'psycopg2'
  14     call_hostpython_via_targetpython = False
  15 
  16     def prebuild_arch(self, arch):
  17         libdir = self.ctx.get_libs_dir(arch.arch)
  18         with current_directory(self.get_build_dir(arch.arch)):
  19             # pg_config_helper will return the system installed libpq, but we
  20             # need the one we just cross-compiled
  21             shprint(sh.sed, '-i',
  22                     "s|pg_config_helper.query(.libdir.)|'{}'|".format(libdir),
  23                     'setup.py')
  24 
  25     def get_recipe_env(self, arch):
  26         env = super(Psycopg2Recipe, self).get_recipe_env(arch)
  27         env['LDFLAGS'] = "{} -L{}".format(env['LDFLAGS'], self.ctx.get_libs_dir(arch.arch))
  28         env['EXTRA_CFLAGS'] = "--host linux-armv"
  29         return env
  30 
  31     def install_python_package(self, arch, name=None, env=None, is_dir=True):
  32         '''Automate the installation of a Python package (or a cython
  33         package where the cython components are pre-built).'''
  34         if env is None:
  35             env = self.get_recipe_env(arch)
  36 
  37         with current_directory(self.get_build_dir(arch.arch)):
  38             hostpython = sh.Command(self.ctx.hostpython)
  39 
  40             shprint(hostpython, 'setup.py', 'build_ext', '--static-libpq',
  41                     _env=env)
  42             shprint(hostpython, 'setup.py', 'install', '-O2',
  43                     '--root={}'.format(self.ctx.get_python_install_dir()),
  44                     '--install-lib=lib/python2.7/site-packages', _env=env)
  45 
  46 
  47 recipe = Psycopg2Recipe()
  48
  [end of pythonforandroid/recipes/psycopg2/__init__.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pythonforandroid/recipes/psycopg2/__init__.py b/pythonforandroid/recipes/psycopg2/__init__.py
  --- a/pythonforandroid/recipes/psycopg2/__init__.py
  +++ b/pythonforandroid/recipes/psycopg2/__init__.py
  @@ -6,6 +6,9 @@
   class Psycopg2Recipe(PythonRecipe):
       """
       Requires `libpq-dev` system dependency e.g. for `pg_config` binary.
  +    If you get `nl_langinfo` symbol runtime error, make sure you're running on
  +    `ANDROID_API` (`ndk-api`) >= 26, see:
  +    https://github.com/kivy/python-for-android/issues/1711#issuecomment-465747557
       """
       version = 'latest'
       url = 'http://initd.org/psycopg/tarballs/psycopg2-{version}.tar.gz'
  @@ -41,7 +44,7 @@
                       _env=env)
               shprint(hostpython, 'setup.py', 'install', '-O2',
                       '--root={}'.format(self.ctx.get_python_install_dir()),
  -                    '--install-lib=lib/python2.7/site-packages', _env=env)
  +                    '--install-lib=.', _env=env)
   
   
   recipe = Psycopg2Recipe()
  
verification_info: {"golden_diff": "diff --git a/pythonforandroid/recipes/psycopg2/__init__.py b/pythonforandroid/recipes/psycopg2/__init__.py\n--- a/pythonforandroid/recipes/psycopg2/__init__.py\n+++ b/pythonforandroid/recipes/psycopg2/__init__.py\n@@ -6,6 +6,9 @@\n class Psycopg2Recipe(PythonRecipe):\n     \"\"\"\n     Requires `libpq-dev` system dependency e.g. for `pg_config` binary.\n+    If you get `nl_langinfo` symbol runtime error, make sure you're running on\n+    `ANDROID_API` (`ndk-api`) >= 26, see:\n+    https://github.com/kivy/python-for-android/issues/1711#issuecomment-465747557\n     \"\"\"\n     version = 'latest'\n     url = 'http://initd.org/psycopg/tarballs/psycopg2-{version}.tar.gz'\n@@ -41,7 +44,7 @@\n                     _env=env)\n             shprint(hostpython, 'setup.py', 'install', '-O2',\n                     '--root={}'.format(self.ctx.get_python_install_dir()),\n-                    '--install-lib=lib/python2.7/site-packages', _env=env)\n+                    '--install-lib=.', _env=env)\n \n \n recipe = Psycopg2Recipe()\n", "issue": "Psycopg2 error after the apk installation.\n![erro psycopg](https://user-images.githubusercontent.com/39860703/52805033-d8002480-306c-11e9-931b-87bc567e70f0.PNG)\r\n\r\nI got this error while debugging the android apk. I associate this to Buildozer because I specified into the buildozer.spec requirements the psycopg2 library. It means that is not working.\r\n\r\nHow do I fix it? I know that is a recipe for psycopg2 here: https://github.com/kivy/python-for-android/blob/master/pythonforandroid/recipes/psycopg2/__init__.py\r\n\r\nHow can I add this recipe to my project, to buildozer compile it successfully ?\n", "before_files": [{"content": "from pythonforandroid.recipe import PythonRecipe\nfrom pythonforandroid.toolchain import current_directory, shprint\nimport sh\n\n\nclass Psycopg2Recipe(PythonRecipe):\n    \"\"\"\n    Requires `libpq-dev` system dependency e.g. for `pg_config` binary.\n    \"\"\"\n    version = 'latest'\n    url = 'http://initd.org/psycopg/tarballs/psycopg2-{version}.tar.gz'\n    depends = ['libpq']\n    site_packages_name = 'psycopg2'\n    call_hostpython_via_targetpython = False\n\n    def prebuild_arch(self, arch):\n        libdir = self.ctx.get_libs_dir(arch.arch)\n        with current_directory(self.get_build_dir(arch.arch)):\n            # pg_config_helper will return the system installed libpq, but we\n            # need the one we just cross-compiled\n            shprint(sh.sed, '-i',\n                    \"s|pg_config_helper.query(.libdir.)|'{}'|\".format(libdir),\n                    'setup.py')\n\n    def get_recipe_env(self, arch):\n        env = super(Psycopg2Recipe, self).get_recipe_env(arch)\n        env['LDFLAGS'] = \"{} -L{}\".format(env['LDFLAGS'], self.ctx.get_libs_dir(arch.arch))\n        env['EXTRA_CFLAGS'] = \"--host linux-armv\"\n        return env\n\n    def install_python_package(self, arch, name=None, env=None, is_dir=True):\n        '''Automate the installation of a Python package (or a cython\n        package where the cython components are pre-built).'''\n        if env is None:\n            env = self.get_recipe_env(arch)\n\n        with current_directory(self.get_build_dir(arch.arch)):\n            hostpython = sh.Command(self.ctx.hostpython)\n\n            shprint(hostpython, 'setup.py', 'build_ext', '--static-libpq',\n                    _env=env)\n            shprint(hostpython, 'setup.py', 'install', '-O2',\n                    '--root={}'.format(self.ctx.get_python_install_dir()),\n                    '--install-lib=lib/python2.7/site-packages', _env=env)\n\n\nrecipe = Psycopg2Recipe()\n", "path": "pythonforandroid/recipes/psycopg2/__init__.py"}]}