enable Windows user to create symbolic links

Windows users may not have permission to create a symbolic link by default. This can result in errors from Python like:

from pathlib import Path

Path('x').touch()
Path('x').symlink_to('y')

or

import os

os.symlink('x', 'y')

OSError: symbolic link privilege not held

Fix

Put Windows into Developer Mode: Settings → Updates & Security → For Developers → Use developer features: Select “Developer mode”

Restart computer, and once again try Python script above to see that Python can create symbolic links.

If it’s still not possible to create symbolic links, you may simply need to use Python ≥ 3.8.

Group Policy

If your version of Windows has it, press Windows + R key (run dialog) and type

gpedit.msc

If you don’t have this, you will need to use Python ≥ 3.8 with Windows in Developer Mode as above.


Navigate to create user permission to create symbolic links:

Computer Configuration → Windows Settings → Security Settings → Local Policies → User Rights Assignment → Create symbolic links

type the user name and click “Check Names” then OK.

Reboot the computer (or logoff, logon) to make the permissions take effect.

References

  • Python os.symlink() on Windows generally requires Python ≥ 3.8

Create symbolic links on Windows