We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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 ?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pythonforandroid/recipes/psycopg2/__init__.py`
Content:
```
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 FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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()

{"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"}], "after_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    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    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=.', _env=env)\n\n\nrecipe = Psycopg2Recipe()\n", "path": "pythonforandroid/recipes/psycopg2/__init__.py"}]}