O
O
Oleg-san2017-04-28 09:35:25
PyQt
Oleg-san, 2017-04-28 09:35:25

How to run PyQt5 in virtualenv on Windows?

There is a python (3.6.1) virtual environment in which the following packages are installed (using pip):

(virtual) F:\pyqt2>pip freeze
appdirs==1.4.3
packaging==16.8
pyparsing==2.2.0
PyQt5==5.8.2
sip==4.19.2
six==1.10.0

In the same environment, I am trying to run the following code:
import sys
from PyQt5.QtWidgets import QApplication, QWidget


if __name__ == '__main__':

    app = QApplication(sys.argv)

    w = QWidget()
    w.resize(250, 150)
    w.move(300, 300)
    w.setWindowTitle('Simple')
    w.show()

    sys.exit(app.exec_())

When I try to run it, I get an error:
(virtual) F:\pyqt2>python run.py
Traceback (most recent call last):
  File "run.py", line 2, in <module>
    from PyQt5.QtWidgets import QApplication, QWidget
ImportError: DLL load failed: Не найден указанный модуль.

It is not clear from the text of the error which dll it is trying to load (
At the same time, if you simply import PyQt and display path, you can see that qt adds the correct path to the folder with dll files.
>>> import os
>>> import pprint
>>> import PyQt5
>>>
>>> pprint.pprint(os.environ['PATH'])
('F:\\pyqt2\\virtual\\lib\\site-packages\\PyQt5\\Qt\\bin;F:\\pyqt2\\virtual\\Scripts; ...'
 ...)
>>>

And if you install PyQt5 not in a virtual environment, then the code above runs without problems and a window appears.
Actually the question is: what needs to be done to make PyQt work in a virtual environment (virtualenv)?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question