We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
allow non-root installation on Linux
I want to install Electrum on my Ubuntu machine in my user's `$HOME` directory, i.e., not via `sudo`.  If I run the command

```
pip install https://download.electrum.org/2.5.4/Electrum-2.5.4.tar.gz
```

I get an error when the installation tries to create a desktop shortcut:

```
copying electrum.desktop -> /usr/share/applications/

error: [Errno 13] Permission denied: '/usr/share/applications/electrum.desktop'
```

Maybe the installation script could `try` if this copy operation works, and try again at `$HOME/.local/share/applications` (or, better, `$XDG_DATA_HOME/applications`) in case it doesn't.

If you agree this would make sense and point me to the file where I would need to do this, I'd be happy to provide a PR.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
1 #!/usr/bin/env python2
2 
3 # python setup.py sdist --format=zip,gztar
4 
5 from setuptools import setup
6 import os
7 import sys
8 import platform
9 import imp
10 
11 version = imp.load_source('version', 'lib/version.py')
12 
13 if sys.version_info[:3] < (2, 7, 0):
14     sys.exit("Error: Electrum requires Python version >= 2.7.0...")
15 
16 data_files = []
17 
18 if platform.system() in ['Linux', 'FreeBSD', 'DragonFly']:
19     usr_share = os.path.join(sys.prefix, "share")
20     data_files += [
21         (os.path.join(usr_share, 'applications/'), ['electrum.desktop']),
22         (os.path.join(usr_share, 'pixmaps/'), ['icons/electrum.png'])
23     ]
24 
25 setup(
26     name="Electrum",
27     version=version.ELECTRUM_VERSION,
28     install_requires=[
29         'slowaes>=0.1a1',
30         'ecdsa>=0.9',
31         'pbkdf2',
32         'requests',
33         'qrcode',
34         'protobuf',
35         'dnspython',
36         'jsonrpclib',
37     ],
38     packages=[
39         'electrum',
40         'electrum_gui',
41         'electrum_gui.qt',
42         'electrum_plugins',
43         'electrum_plugins.audio_modem',
44         'electrum_plugins.cosigner_pool',
45         'electrum_plugins.email_requests',
46         'electrum_plugins.exchange_rate',
47         'electrum_plugins.greenaddress_instant',
48         'electrum_plugins.keepkey',
49         'electrum_plugins.labels',
50         'electrum_plugins.ledger',
51         'electrum_plugins.plot',
52         'electrum_plugins.trezor',
53         'electrum_plugins.trustedcoin',
54         'electrum_plugins.virtualkeyboard',
55     ],
56     package_dir={
57         'electrum': 'lib',
58         'electrum_gui': 'gui',
59         'electrum_plugins': 'plugins',
60     },
61     package_data={
62         'electrum': [
63             'www/index.html',
64             'wordlist/*.txt',
65             'locale/*/LC_MESSAGES/electrum.mo',
66         ]
67     },
68     scripts=['electrum'],
69     data_files=data_files,
70     description="Lightweight Bitcoin Wallet",
71     author="Thomas Voegtlin",
72     author_email="thomasv@electrum.org",
73     license="GNU GPLv3",
74     url="https://electrum.org",
75     long_description="""Lightweight Bitcoin Wallet"""
76 )
77
```
--- 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/setup.py b/setup.py
old mode 100644
new mode 100755
--- a/setup.py
+++ b/setup.py
@@ -17,6 +17,11 @@
 
 if platform.system() in ['Linux', 'FreeBSD', 'DragonFly']:
     usr_share = os.path.join(sys.prefix, "share")
+    if not os.access(usr_share, os.W_OK):
+        if 'XDG_DATA_HOME' in os.environ.keys():
+            usr_share = os.environ['$XDG_DATA_HOME']
+        else:
+            usr_share = os.path.expanduser('~/.local/share')
     data_files += [
         (os.path.join(usr_share, 'applications/'), ['electrum.desktop']),
         (os.path.join(usr_share, 'pixmaps/'), ['icons/electrum.png'])

{"golden_diff": "diff --git a/setup.py b/setup.py\nold mode 100644\nnew mode 100755\n--- a/setup.py\n+++ b/setup.py\n@@ -17,6 +17,11 @@\n \n if platform.system() in ['Linux', 'FreeBSD', 'DragonFly']:\n     usr_share = os.path.join(sys.prefix, \"share\")\n+    if not os.access(usr_share, os.W_OK):\n+        if 'XDG_DATA_HOME' in os.environ.keys():\n+            usr_share = os.environ['$XDG_DATA_HOME']\n+        else:\n+            usr_share = os.path.expanduser('~/.local/share')\n     data_files += [\n         (os.path.join(usr_share, 'applications/'), ['electrum.desktop']),\n         (os.path.join(usr_share, 'pixmaps/'), ['icons/electrum.png'])\n", "issue": "allow non-root installation on Linux\nI want to install Electrum on my Ubuntu machine in my user's `$HOME` directory, i.e., not via `sudo`.  If I run the command\n\n```\npip install https://download.electrum.org/2.5.4/Electrum-2.5.4.tar.gz\n```\n\nI get an error when the installation tries to create a desktop shortcut:\n\n```\ncopying electrum.desktop -> /usr/share/applications/\n\nerror: [Errno 13] Permission denied: '/usr/share/applications/electrum.desktop'\n```\n\nMaybe the installation script could `try` if this copy operation works, and try again at `$HOME/.local/share/applications` (or, better, `$XDG_DATA_HOME/applications`) in case it doesn't.\n\nIf you agree this would make sense and point me to the file where I would need to do this, I'd be happy to provide a PR.\n\n", "before_files": [{"content": "#!/usr/bin/env python2\n\n# python setup.py sdist --format=zip,gztar\n\nfrom setuptools import setup\nimport os\nimport sys\nimport platform\nimport imp\n\nversion = imp.load_source('version', 'lib/version.py')\n\nif sys.version_info[:3] < (2, 7, 0):\n    sys.exit(\"Error: Electrum requires Python version >= 2.7.0...\")\n\ndata_files = []\n\nif platform.system() in ['Linux', 'FreeBSD', 'DragonFly']:\n    usr_share = os.path.join(sys.prefix, \"share\")\n    data_files += [\n        (os.path.join(usr_share, 'applications/'), ['electrum.desktop']),\n        (os.path.join(usr_share, 'pixmaps/'), ['icons/electrum.png'])\n    ]\n\nsetup(\n    name=\"Electrum\",\n    version=version.ELECTRUM_VERSION,\n    install_requires=[\n        'slowaes>=0.1a1',\n        'ecdsa>=0.9',\n        'pbkdf2',\n        'requests',\n        'qrcode',\n        'protobuf',\n        'dnspython',\n        'jsonrpclib',\n    ],\n    packages=[\n        'electrum',\n        'electrum_gui',\n        'electrum_gui.qt',\n        'electrum_plugins',\n        'electrum_plugins.audio_modem',\n        'electrum_plugins.cosigner_pool',\n        'electrum_plugins.email_requests',\n        'electrum_plugins.exchange_rate',\n        'electrum_plugins.greenaddress_instant',\n        'electrum_plugins.keepkey',\n        'electrum_plugins.labels',\n        'electrum_plugins.ledger',\n        'electrum_plugins.plot',\n        'electrum_plugins.trezor',\n        'electrum_plugins.trustedcoin',\n        'electrum_plugins.virtualkeyboard',\n    ],\n    package_dir={\n        'electrum': 'lib',\n        'electrum_gui': 'gui',\n        'electrum_plugins': 'plugins',\n    },\n    package_data={\n        'electrum': [\n            'www/index.html',\n            'wordlist/*.txt',\n            'locale/*/LC_MESSAGES/electrum.mo',\n        ]\n    },\n    scripts=['electrum'],\n    data_files=data_files,\n    description=\"Lightweight Bitcoin Wallet\",\n    author=\"Thomas Voegtlin\",\n    author_email=\"thomasv@electrum.org\",\n    license=\"GNU GPLv3\",\n    url=\"https://electrum.org\",\n    long_description=\"\"\"Lightweight Bitcoin Wallet\"\"\"\n)\n", "path": "setup.py"}], "after_files": [{"content": "#!/usr/bin/env python2\n\n# python setup.py sdist --format=zip,gztar\n\nfrom setuptools import setup\nimport os\nimport sys\nimport platform\nimport imp\n\nversion = imp.load_source('version', 'lib/version.py')\n\nif sys.version_info[:3] < (2, 7, 0):\n    sys.exit(\"Error: Electrum requires Python version >= 2.7.0...\")\n\ndata_files = []\n\nif platform.system() in ['Linux', 'FreeBSD', 'DragonFly']:\n    usr_share = os.path.join(sys.prefix, \"share\")\n    if not os.access(usr_share, os.W_OK):\n        if 'XDG_DATA_HOME' in os.environ.keys():\n            usr_share = os.environ['$XDG_DATA_HOME']\n        else:\n            usr_share = os.path.expanduser('~/.local/share')\n    data_files += [\n        (os.path.join(usr_share, 'applications/'), ['electrum.desktop']),\n        (os.path.join(usr_share, 'pixmaps/'), ['icons/electrum.png'])\n    ]\n\nsetup(\n    name=\"Electrum\",\n    version=version.ELECTRUM_VERSION,\n    install_requires=[\n        'slowaes>=0.1a1',\n        'ecdsa>=0.9',\n        'pbkdf2',\n        'requests',\n        'qrcode',\n        'protobuf',\n        'dnspython',\n        'jsonrpclib',\n    ],\n    packages=[\n        'electrum',\n        'electrum_gui',\n        'electrum_gui.qt',\n        'electrum_plugins',\n        'electrum_plugins.audio_modem',\n        'electrum_plugins.cosigner_pool',\n        'electrum_plugins.email_requests',\n        'electrum_plugins.exchange_rate',\n        'electrum_plugins.greenaddress_instant',\n        'electrum_plugins.keepkey',\n        'electrum_plugins.labels',\n        'electrum_plugins.ledger',\n        'electrum_plugins.plot',\n        'electrum_plugins.trezor',\n        'electrum_plugins.trustedcoin',\n        'electrum_plugins.virtualkeyboard',\n    ],\n    package_dir={\n        'electrum': 'lib',\n        'electrum_gui': 'gui',\n        'electrum_plugins': 'plugins',\n    },\n    package_data={\n        'electrum': [\n            'www/index.html',\n            'wordlist/*.txt',\n            'locale/*/LC_MESSAGES/electrum.mo',\n        ]\n    },\n    scripts=['electrum'],\n    data_files=data_files,\n    description=\"Lightweight Bitcoin Wallet\",\n    author=\"Thomas Voegtlin\",\n    author_email=\"thomasv@electrum.org\",\n    license=\"GNU GPLv3\",\n    url=\"https://electrum.org\",\n    long_description=\"\"\"Lightweight Bitcoin Wallet\"\"\"\n)\n", "path": "setup.py"}]}