0

I'm struggling to figure out how to include the PyQt module in my Python project. I have tried downloading it from here as a zip file, then including that directory in an environment variable that I called PYTHONPATH. I am running Windows 10, Python 3.5.1, and using PyCharm for my IDE. I was trying to follow the instructions from this question on stackoverflow but I haven't had success and am clearly unsure how to do it.

When I downloaded Python, it was downloaded to my appData folder. The path is as follows users/me/AppData/Local/Programs/Python/Python 35-32...and then a bunch of stuff is in therefor Python. I downloaded the PyQt zip folder and unzipped it to the users/me/AppData/Local/Programs/Python/. After adding the environment variable, PyCharm still isn't able to use the module saying ImportError: No module named 'PyQt4. Can anyone explain how I can import this module successfully? I'm used to Javascript...is there a way to just reference the file? Kind of like how this other stack overflow question is doing it?

Here are the imports that I need:

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtWebKit import *

Thanks in advance!

Community
  • 1
  • 1
Jaromjj
  • 326
  • 3
  • 17

2 Answers2

0

This is how i install Python and PyQt

1 - Install python (Create a folder somewhere like D:\python_dist)

2 - Install Qt

3 - Install PyQt5/PyQt4 with Windows installer ( PyQt5-5.6-gpl-Py3.5-Qt5.6.0-x64-2.exe) https://www.riverbankcomputing.com/software/pyqt/download5

4 - Check paths ...

5 - Open your IDE then try

When you do python, usually you use a virtual_env, and you could need several env, that's why i recommand to create a special python folder

PyNico
  • 695
  • 5
  • 21
  • Is there a difference between steps 2 and 3? – Jaromjj Jun 17 '16 at 13:31
  • Yes, you need to have Qt to use PyQt, PyQt is just a wrapper to use Qt's libraries – PyNico Jun 17 '16 at 13:33
  • I can't find where to download Qt. All of the search results in google bring up PyQt. Do you know where I can go to download it? – Jaromjj Jun 17 '16 at 14:21
  • Sounds good. Thank you for finding that. With Step 4...do all of these things need to be installed in the same place? So I have all of the python stuff (python.exe and all the folders), in a folder called 'Python 35-32', should I download Qt and PyQt to this same folder? – Jaromjj Jun 17 '16 at 14:50
  • nop, and you should not have Qt and PyQt in the same folder, PyQt is in python, ( lib/site-packages) and Qt is w/e (if you need to package your app, having Qt in Python folder will make pour package too heavy) – PyNico Jun 17 '16 at 14:55
  • Once I have downloaded Qt, and PyQt, how will the python program know where to find everything? Will I have to restart PyCharm? Qt is downloading right now, and the default location was C:\Qt. – Jaromjj Jun 18 '16 at 16:55
0

If you are having trouble installing the PyQt library from binary and from pip you could install PyQt from prepackaged whl files.

navigate to the Unofficial Windows Binaries from the University of California, Irvine and download the whl associated with your installed version of Python: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4

Then insall that file via pip by navigating to the directory where you downloaded the whl file via command line and typing in the following:

pip install name-of-whl-file.whl

You also may have to install pip. If that is the case visit this site to learn how to do that: https://pip.pypa.io/en/stable/installing/

Jaxian
  • 1,146
  • 7
  • 14
  • When I download the whl file do I need to download it to my python directory where the python.exe file is? – Jaromjj Jun 17 '16 at 14:22
  • pip is a python tools, if you have it (you should), and have python/scripts in your path, you just have to use the command above and it will install it in your python (usually in Python\Lib\site-packages). ( But pip/whl PyQt install rarely work, in my experience), – PyNico Jun 17 '16 at 14:40
  • Jaromjj: Like PyNico said, you can run that whl file from any directory with the pip command I explained above - just as long as you have your python/scripts directory in your system's path. As an example, if you have Python 2.7 installed in C:\Python27, go to System Properties in Windows and add "C:\Python27\Scripts" to your path. Also, in my experience UC Irvine's prebuilt whl packages have always worked. – Jaxian Jun 17 '16 at 21:50
  • Hey, unsure where to install the whl. the whl file is in my downloads folder, but pip is in my python/scripts folder. What directory should cmd be in when I issue the command you listed above? – Jaromjj Jun 18 '16 at 17:14
  • You should be able to run the pip command from any directory on your computer (the only requirement is that you run it from the same dir you have your whl file). But, it seems you are not understanding the concept of the Path. When you add a directory to your Windows system path you are able to access the contents of that directory from any place on your computer. You should read up on this. What is the path?: http://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them How to set up the path: http://www.computerhope.com/issues/ch000549.htm – Jaxian Jun 19 '16 at 06:58