Error importing/installing PyQt
Question: I am having a ton of trouble with PyQt. I downloaded the binary installer,
made sure it was the right version, (4.15.5, 64-bit) and thought I was done.
Now, I have two problems, which totally stop me from using it with Python.
First of all, when I enter 'from pyqt4 import qtcore' (or something along
those lines, I'm not looking at the command right now) it returns
'ImportError: No module named "pyqt4"'. So I thought I might try making a form
in designer and using pyuic to convert it. Nope. Apparently, 'pyuic is not a
recognized command or file'. It seems like I did something wrong, but I've re-
installed both Python and PyQt several times and spent hours searching the
web. What is happening?

PS, there is no 'bin' folder, I looked at that question too...

PPS, I'm running Python 3.3.3 on a Windows 7 machine.


Answer: On Windows, Python packages are installed to Python's installation directory
in Lib\site-packages (e.g. C:\Python33\Lib\site-packages\PyQt4). Scripts
install to the "Scripts" directory (e.g. C:\Python33\Scripts). The installer
should have also created a shortcut to Qt Designer in the Start menu.

Imports are case sensitive even on Windows:

    
    
    from PyQt4 import QtCore
    

For the `pyuic` command, there's a batch file named pyuic4.bat in the package
directory. Personally I'd skip on this1. The actual script is
PyQt4\uic\pyuic.py. I'd use a Windows shortcut2, or use an NTFS symlink3
created with cmd's [`mklink`](http://ss64.com/nt/mklink.html) or Python's
[`os.symlink`](https://docs.python.org/3/library/os.html#os.symlink). You
could also just copy the script, but that's a problem if the original gets
updated.

* * *

1\. A batch file's `Ctrl-C` handler is an annoying prompt that's only relevant
to actual batch processing.

2\. To use the shortcut like a normal command, just add the `.LNK` file
extension to the `PATHEXT` environment variable. Here's the way to create a
simple shortcut in Python (requires PyWin32):

    
    
    import win32com.client
    ws = win32com.client.Dispatch('wscript.shell')
    shortcut = ws.CreateShortcut('SHORTCUT_NAME.lnk')
    shortcut.TargetPath = r'"PATH\TO\TARGET"'
    shortcut.Save()
    

3\. Creating symbolic links requires NT 6.0+ and
`SeCreateSymbolicLinkPrivilege`. Check `whoami /priv` to see whether your
account has the privilege. Accounts in the Administrators group have the
privilege, but require access token elevation if UAC is enabled. Regular users
can be granted the privilege.

