Repository: xonsh/xonsh

Issue:
Python 3.7rc0 startup on macOS
I'm getting the following exception output when starting xonsh 0.6.6 under Python-3.7rc0 for the 64-bit macOS build:

```
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/history/json.py", line 111, in run
    files = self.files(only_unlocked=True)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/history/json.py", line 133, in files
    boot = uptime.boottime()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/xoreutils/uptime.py", line 270, in boottime
    up = uptime()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/xoreutils/uptime.py", line 258, in uptime
    up = _UPTIME_FUNCS.get(sys.platform, _uptime_bsd)()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/xoreutils/uptime.py", line 30, in _uptime_osx
    bt = xlimps.macutils.sysctlbyname(b"kern.boottime", return_str=False)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/macutils.py", line 14, in sysctlbyname
    LIBC.sysctlbyname(name, None, byref(size), None, 0)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/lazyasd.py", line 60, in __getattribute__
    obj = self._lazy_obj()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/lazyasd.py", line 52, in _lazy_obj
    obj = d['load']()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/platform.py", line 491, in LIBC
    libc = ctypes.CDLL(ctypes.util.find_library("c"))
AttributeError: module 'ctypes' has no attribute 'util'

```
after the exception the normal startup of xonsh seems to occur:

```
                       Welcome to the xonsh shell (0.6.6)

                ~ With great shell comes great reproducibility ~

--------------------------------------------------------------------------------
xonfig tutorial    ->    Launch the tutorial in the browser
xonfig wizard      ->    Run the configuration wizard and claim your shell
(Note: Run the Wizard or create a ~/.xonshrc file to suppress the welcome screen)

```

followed by the prompt.

Here are the installed packages:

```
Package        Version
-------------- ---------
certifi        2018.4.16
docopt         0.6.2
jedi           0.12.0
parso          0.2.1
pip            10.0.1
prompt-toolkit 1.0.15
ptpython       0.41
Pygments       2.2.0
setuptools     39.0.1
six            1.11.0
wcwidth        0.1.7
xonsh          0.6.6
```


Discussion:
Thanks for reporting @alexis-layton! Can you also please provide the output of the `xonfig` command?
Oh I guess you can't because it isn't starting up yet
This is the output of xonfig after the error:

```
+------------------+----------------------+
| xonsh            | 0.6.6                |
| Git SHA          | d87b7e5e             |
| Commit Date      | May 24 04:18:39 2018 |
| Python           | 3.7.0                |
| PLY              | 3.9                  |
| have readline    | True                 |
| prompt toolkit   | 1.0.15               |
| shell type       | prompt_toolkit       |
| pygments         | 2.2.0                |
| on posix         | True                 |
| on linux         | False                |
| on darwin        | True                 |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
+------------------+----------------------+
```

The error occurs on macOS High Sierra 10.13.5 (MacPro 5,1) and also on a MacBook Air running the latest 10.11 El Capitan version.

Resolving patch:
diff --git a/xonsh/platform.py b/xonsh/platform.py
--- a/xonsh/platform.py
+++ b/xonsh/platform.py
@@ -116,14 +116,14 @@ def pygments_version():
 
 @functools.lru_cache(1)
 def has_prompt_toolkit():
-    """ Tests if the `prompt_toolkit` is available. """
+    """Tests if the `prompt_toolkit` is available."""
     spec = importlib.util.find_spec('prompt_toolkit')
     return (spec is not None)
 
 
 @functools.lru_cache(1)
 def ptk_version():
-    """ Returns `prompt_toolkit.__version__` if available, else ``None``. """
+    """Returns `prompt_toolkit.__version__` if available, else ``None``."""
     if has_prompt_toolkit():
         import prompt_toolkit
         return getattr(prompt_toolkit, '__version__', '<0.57')
@@ -487,7 +487,9 @@ def PATH_DEFAULT():
 @lazyobject
 def LIBC():
     """The platform dependent libc implementation."""
+    global ctypes
     if ON_DARWIN:
+        import ctypes.util
         libc = ctypes.CDLL(ctypes.util.find_library("c"))
     elif ON_CYGWIN:
         libc = ctypes.CDLL('cygwin1.dll')


Test patch: