title: How to handle symlinks in Python for cross-platform execution?
body: <p>I am creating a Python 2.7 script to automate an environment setup which is to be used on Windows and Linux (Ubuntu) systems, preferably with vanilla Python.</p>
  <p>I am having trouble getting Python to create a symlink on Windows (I'm sure it's much simpler on Linux), and based on approaches from other Stack Overflow questions, I've still not been able to get this to work.</p>
  <p>My first approach was to simply use <code>os.symlink</code> in a very simple method</p>
  <pre><code>def createSymlink(source, dest):
      os.symlink(source,dest)
  </code></pre>
  <p>But this returns an error:
  <code>AttributeError: 'module' object has no attribute 'symlink'</code></p>
  <p>After more searching, I tried another approach based on [this][1] answer, but I get a similar error.</p>
  <pre><code>  File &quot;C:/Workspace/PythonProjects/architect/main.py&quot;, line 94, in createSymlink
      os.symlink = symlink_ms(source, dest)
    File &quot;C:/Workspace/PythonProjects/architect/main.py&quot;, line 86, in symlink_ms
      csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_unit32)
  AttributeError: 'module' object has no attribute 'c_unit32'
  </code></pre>
  <p>My code for this approach is as follows, and <code>_OS == 'Windows'</code> is True.</p>
  <pre><code>def createSymlink(source, dest):
      if _OS == 'Windows':
          def symlink_ms(source, dest):
              import ctypes
              csl = ctypes.windll.kernel32.CreateSymbolicLinkW
              csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_unit32)
              csl.restype = ctypes.c_ubyte
              flags = 1 if os.path.isdir(source) else 0
              try:
                  if csl(dest, source.replace('/', '\\'), flags) == 0:
                      raise ctypes.WinError()
              except:
                  pass
          os.symlink = symlink_ms(source, dest)
  </code></pre>
  <p>I am very new to Python, so I may be looking at this entirely wrong, but is there a way to get this working without pulling in third party libraries?
  [1]: <a href="https://stackoverflow.com/a/8464306/5134416">https://stackoverflow.com/a/8464306/5134416</a></p>