We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
nnictl package install not working for venv
It seems that `nnictl package install` makes the package going to user level, which makes it not accessible from a venv.

Warning:

```
Installing collected packages: ConfigSpaceNNI, docutils, pynisher, pyrfr, sphinxcontrib-htmlhelp, sphinxcontrib-qthelp, sphinxcontrib-devhelp, imagesize, Jinja2, sphinxcontrib-applehelp, alabaster, sphinxcontrib-jsmath, Pygments, snowballstemmer, sphinxcontrib-serializinghtml, packaging, sphinx, sphinx-rtd-theme, smac
  Running setup.py install for ConfigSpaceNNI ... done
  The script pygmentize is installed in '/home/zhangyuge/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  Running setup.py install for snowballstemmer ... done
  The scripts sphinx-apidoc, sphinx-autogen, sphinx-build and sphinx-quickstart are installed in '/home/zhangyuge/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  Running setup.py install for smac ... done
```

Corresponding code:

https://github.com/microsoft/nni/blob/958efabf066b975a5cdcde293c9de33ec1430cb2/tools/nni_cmd/command_utils.py#L49

We could consider removing this `--user`.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `tools/nni_cmd/command_utils.py`
Content:
```
1 from subprocess import call, check_output
2 import sys
3 import os
4 import signal
5 import psutil
6 from .common_utils import  print_error, print_normal, print_warning
7 
8 def check_output_command(file_path, head=None, tail=None):
9     '''call check_output command to read content from a file'''
10     if os.path.exists(file_path):
11         if sys.platform == 'win32':
12             cmds = ['powershell.exe', 'type', file_path]
13             if head:
14                 cmds += ['|', 'select', '-first', str(head)]
15             elif tail:
16                 cmds += ['|', 'select', '-last', str(tail)]
17             return check_output(cmds, shell=True).decode('utf-8')
18         else:
19             cmds = ['cat', file_path]
20             if head:
21                 cmds = ['head', '-' + str(head), file_path]
22             elif tail:
23                 cmds = ['tail', '-' + str(tail), file_path]
24             return check_output(cmds, shell=False).decode('utf-8')
25     else:
26         print_error('{0} does not exist!'.format(file_path))
27         exit(1)
28 
29 def kill_command(pid):
30     '''kill command'''
31     if sys.platform == 'win32':
32         process = psutil.Process(pid=pid)
33         process.send_signal(signal.CTRL_BREAK_EVENT)
34     else:
35         cmds = ['kill', str(pid)]
36         call(cmds)
37 
38 def install_package_command(package_name):
39     '''install python package from pip'''
40     #TODO refactor python logic
41     if sys.platform == "win32":
42         cmds = 'python -m pip install --user {0}'.format(package_name)
43     else:
44         cmds = 'python3 -m pip install --user {0}'.format(package_name)
45     call(cmds, shell=True)
46 
47 def install_requirements_command(requirements_path):
48     '''install requirements.txt'''
49     cmds = 'cd ' + requirements_path + ' && {0} -m pip install --user -r requirements.txt'
50     #TODO refactor python logic
51     if sys.platform == "win32":
52         cmds = cmds.format('python')
53     else:
54         cmds = cmds.format('python3')
55     call(cmds, shell=True)
56
```
--- 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/tools/nni_cmd/command_utils.py b/tools/nni_cmd/command_utils.py
--- a/tools/nni_cmd/command_utils.py
+++ b/tools/nni_cmd/command_utils.py
@@ -3,10 +3,11 @@
 import os
 import signal
 import psutil
-from .common_utils import  print_error, print_normal, print_warning
+from .common_utils import print_error, print_normal, print_warning
+
 
 def check_output_command(file_path, head=None, tail=None):
-    '''call check_output command to read content from a file'''
+    """call check_output command to read content from a file"""
     if os.path.exists(file_path):
         if sys.platform == 'win32':
             cmds = ['powershell.exe', 'type', file_path]
@@ -26,8 +27,9 @@
         print_error('{0} does not exist!'.format(file_path))
         exit(1)
 
+
 def kill_command(pid):
-    '''kill command'''
+    """kill command"""
     if sys.platform == 'win32':
         process = psutil.Process(pid=pid)
         process.send_signal(signal.CTRL_BREAK_EVENT)
@@ -35,21 +37,35 @@
         cmds = ['kill', str(pid)]
         call(cmds)
 
+
 def install_package_command(package_name):
-    '''install python package from pip'''
-    #TODO refactor python logic
-    if sys.platform == "win32":
-        cmds = 'python -m pip install --user {0}'.format(package_name)
-    else:
-        cmds = 'python3 -m pip install --user {0}'.format(package_name)
-    call(cmds, shell=True)
+    """
+    Install python package from pip.
+
+    Parameters
+    ----------
+    package_name: str
+        The name of package to be installed.
+    """
+    call(_get_pip_install() + [package_name], shell=False)
+
 
 def install_requirements_command(requirements_path):
-    '''install requirements.txt'''
-    cmds = 'cd ' + requirements_path + ' && {0} -m pip install --user -r requirements.txt'
-    #TODO refactor python logic
-    if sys.platform == "win32":
-        cmds = cmds.format('python')
-    else:
-        cmds = cmds.format('python3')
-    call(cmds, shell=True)
+    """
+    Install packages from `requirements.txt` in `requirements_path`.
+
+    Parameters
+    ----------
+    requirements_path: str
+        Path to the directory that contains `requirements.txt`.
+    """
+    call(_get_pip_install() + ["-r", os.path.join(requirements_path, "requirements.txt")], shell=False)
+
+
+def _get_pip_install():
+    python = "python" if sys.platform == "win32" else "python3"
+    ret = [python, "-m", "pip", "install"]
+    if "CONDA_DEFAULT_ENV" not in os.environ and "VIRTUAL_ENV" not in os.environ and \
+            (sys.platform != "win32" and os.getuid() != 0):  # on unix and not running in root
+        ret.append("--user")  # not in virtualenv or conda
+    return ret

{"golden_diff": "diff --git a/tools/nni_cmd/command_utils.py b/tools/nni_cmd/command_utils.py\n--- a/tools/nni_cmd/command_utils.py\n+++ b/tools/nni_cmd/command_utils.py\n@@ -3,10 +3,11 @@\n import os\n import signal\n import psutil\n-from .common_utils import  print_error, print_normal, print_warning\n+from .common_utils import print_error, print_normal, print_warning\n+\n \n def check_output_command(file_path, head=None, tail=None):\n-    '''call check_output command to read content from a file'''\n+    \"\"\"call check_output command to read content from a file\"\"\"\n     if os.path.exists(file_path):\n         if sys.platform == 'win32':\n             cmds = ['powershell.exe', 'type', file_path]\n@@ -26,8 +27,9 @@\n         print_error('{0} does not exist!'.format(file_path))\n         exit(1)\n \n+\n def kill_command(pid):\n-    '''kill command'''\n+    \"\"\"kill command\"\"\"\n     if sys.platform == 'win32':\n         process = psutil.Process(pid=pid)\n         process.send_signal(signal.CTRL_BREAK_EVENT)\n@@ -35,21 +37,35 @@\n         cmds = ['kill', str(pid)]\n         call(cmds)\n \n+\n def install_package_command(package_name):\n-    '''install python package from pip'''\n-    #TODO refactor python logic\n-    if sys.platform == \"win32\":\n-        cmds = 'python -m pip install --user {0}'.format(package_name)\n-    else:\n-        cmds = 'python3 -m pip install --user {0}'.format(package_name)\n-    call(cmds, shell=True)\n+    \"\"\"\n+    Install python package from pip.\n+\n+    Parameters\n+    ----------\n+    package_name: str\n+        The name of package to be installed.\n+    \"\"\"\n+    call(_get_pip_install() + [package_name], shell=False)\n+\n \n def install_requirements_command(requirements_path):\n-    '''install requirements.txt'''\n-    cmds = 'cd ' + requirements_path + ' && {0} -m pip install --user -r requirements.txt'\n-    #TODO refactor python logic\n-    if sys.platform == \"win32\":\n-        cmds = cmds.format('python')\n-    else:\n-        cmds = cmds.format('python3')\n-    call(cmds, shell=True)\n+    \"\"\"\n+    Install packages from `requirements.txt` in `requirements_path`.\n+\n+    Parameters\n+    ----------\n+    requirements_path: str\n+        Path to the directory that contains `requirements.txt`.\n+    \"\"\"\n+    call(_get_pip_install() + [\"-r\", os.path.join(requirements_path, \"requirements.txt\")], shell=False)\n+\n+\n+def _get_pip_install():\n+    python = \"python\" if sys.platform == \"win32\" else \"python3\"\n+    ret = [python, \"-m\", \"pip\", \"install\"]\n+    if \"CONDA_DEFAULT_ENV\" not in os.environ and \"VIRTUAL_ENV\" not in os.environ and \\\n+            (sys.platform != \"win32\" and os.getuid() != 0):  # on unix and not running in root\n+        ret.append(\"--user\")  # not in virtualenv or conda\n+    return ret\n", "issue": "nnictl package install not working for venv\nIt seems that `nnictl package install` makes the package going to user level, which makes it not accessible from a venv.\r\n\r\nWarning:\r\n\r\n```\r\nInstalling collected packages: ConfigSpaceNNI, docutils, pynisher, pyrfr, sphinxcontrib-htmlhelp, sphinxcontrib-qthelp, sphinxcontrib-devhelp, imagesize, Jinja2, sphinxcontrib-applehelp, alabaster, sphinxcontrib-jsmath, Pygments, snowballstemmer, sphinxcontrib-serializinghtml, packaging, sphinx, sphinx-rtd-theme, smac\r\n  Running setup.py install for ConfigSpaceNNI ... done\r\n  The script pygmentize is installed in '/home/zhangyuge/.local/bin' which is not on PATH.\r\n  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\r\n  Running setup.py install for snowballstemmer ... done\r\n  The scripts sphinx-apidoc, sphinx-autogen, sphinx-build and sphinx-quickstart are installed in '/home/zhangyuge/.local/bin' which is not on PATH.\r\n  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\r\n  Running setup.py install for smac ... done\r\n```\r\n\r\nCorresponding code:\r\n\r\nhttps://github.com/microsoft/nni/blob/958efabf066b975a5cdcde293c9de33ec1430cb2/tools/nni_cmd/command_utils.py#L49\r\n\r\nWe could consider removing this `--user`.\n", "before_files": [{"content": "from subprocess import call, check_output\nimport sys\nimport os\nimport signal\nimport psutil\nfrom .common_utils import  print_error, print_normal, print_warning\n\ndef check_output_command(file_path, head=None, tail=None):\n    '''call check_output command to read content from a file'''\n    if os.path.exists(file_path):\n        if sys.platform == 'win32':\n            cmds = ['powershell.exe', 'type', file_path]\n            if head:\n                cmds += ['|', 'select', '-first', str(head)]\n            elif tail:\n                cmds += ['|', 'select', '-last', str(tail)]\n            return check_output(cmds, shell=True).decode('utf-8')\n        else:\n            cmds = ['cat', file_path]\n            if head:\n                cmds = ['head', '-' + str(head), file_path]\n            elif tail:\n                cmds = ['tail', '-' + str(tail), file_path]\n            return check_output(cmds, shell=False).decode('utf-8')\n    else:\n        print_error('{0} does not exist!'.format(file_path))\n        exit(1)\n\ndef kill_command(pid):\n    '''kill command'''\n    if sys.platform == 'win32':\n        process = psutil.Process(pid=pid)\n        process.send_signal(signal.CTRL_BREAK_EVENT)\n    else:\n        cmds = ['kill', str(pid)]\n        call(cmds)\n\ndef install_package_command(package_name):\n    '''install python package from pip'''\n    #TODO refactor python logic\n    if sys.platform == \"win32\":\n        cmds = 'python -m pip install --user {0}'.format(package_name)\n    else:\n        cmds = 'python3 -m pip install --user {0}'.format(package_name)\n    call(cmds, shell=True)\n\ndef install_requirements_command(requirements_path):\n    '''install requirements.txt'''\n    cmds = 'cd ' + requirements_path + ' && {0} -m pip install --user -r requirements.txt'\n    #TODO refactor python logic\n    if sys.platform == \"win32\":\n        cmds = cmds.format('python')\n    else:\n        cmds = cmds.format('python3')\n    call(cmds, shell=True)\n", "path": "tools/nni_cmd/command_utils.py"}], "after_files": [{"content": "from subprocess import call, check_output\nimport sys\nimport os\nimport signal\nimport psutil\nfrom .common_utils import print_error, print_normal, print_warning\n\n\ndef check_output_command(file_path, head=None, tail=None):\n    \"\"\"call check_output command to read content from a file\"\"\"\n    if os.path.exists(file_path):\n        if sys.platform == 'win32':\n            cmds = ['powershell.exe', 'type', file_path]\n            if head:\n                cmds += ['|', 'select', '-first', str(head)]\n            elif tail:\n                cmds += ['|', 'select', '-last', str(tail)]\n            return check_output(cmds, shell=True).decode('utf-8')\n        else:\n            cmds = ['cat', file_path]\n            if head:\n                cmds = ['head', '-' + str(head), file_path]\n            elif tail:\n                cmds = ['tail', '-' + str(tail), file_path]\n            return check_output(cmds, shell=False).decode('utf-8')\n    else:\n        print_error('{0} does not exist!'.format(file_path))\n        exit(1)\n\n\ndef kill_command(pid):\n    \"\"\"kill command\"\"\"\n    if sys.platform == 'win32':\n        process = psutil.Process(pid=pid)\n        process.send_signal(signal.CTRL_BREAK_EVENT)\n    else:\n        cmds = ['kill', str(pid)]\n        call(cmds)\n\n\ndef install_package_command(package_name):\n    \"\"\"\n    Install python package from pip.\n\n    Parameters\n    ----------\n    package_name: str\n        The name of package to be installed.\n    \"\"\"\n    call(_get_pip_install() + [package_name], shell=False)\n\n\ndef install_requirements_command(requirements_path):\n    \"\"\"\n    Install packages from `requirements.txt` in `requirements_path`.\n\n    Parameters\n    ----------\n    requirements_path: str\n        Path to the directory that contains `requirements.txt`.\n    \"\"\"\n    call(_get_pip_install() + [\"-r\", os.path.join(requirements_path, \"requirements.txt\")], shell=False)\n\n\ndef _get_pip_install():\n    python = \"python\" if sys.platform == \"win32\" else \"python3\"\n    ret = [python, \"-m\", \"pip\", \"install\"]\n    if \"CONDA_DEFAULT_ENV\" not in os.environ and \"VIRTUAL_ENV\" not in os.environ and \\\n            (sys.platform != \"win32\" and os.getuid() != 0):  # on unix and not running in root\n        ret.append(\"--user\")  # not in virtualenv or conda\n    return ret\n", "path": "tools/nni_cmd/command_utils.py"}]}