Installation of PyQt4 - python

I currently begin to use Python (2.7) with Eclipse(on windows). To run my script,I would need PyQt4 but I meet some problems when I try to install it.
I downloaded
PyQt4-4.10.3-gpl-Py2.7-Qt4.8.5-x64.exe,
PyQt-win-gpl-4.10.3.zip
and sip-4.15.2.zip
from the following link: http://www.riverbankcomputing.co.uk/software/pyqt/download .
I launched the execution of the first feature and a folder PyQt4 appeared into C:\Python27\Lib\site-packages.
To my mind, PyQt4 installation was finished and I simply did:
Eclipse>Preferences>Pydev>Interpreter-Python>python27>Apply
Nevertheless, when I try to import any function of PyQt4, I am said that the module name is unknown.
Could you help me to solve this problem?
Thank you very much

I want to comment for this .... but my reputation doesn't allow me to :(
anyway You could try this answer ..... (link below)
which is something like that :
Copy from This Answer
PyQt is actually a wrapping of C++ Qt libraries. So they are not .py
files an
d PyDev can't analyze them to
get what is in them. You need to add PyQt4 in the Forced Builtins tab,
so that PyDev can use a Python shell to "look into" those libraries
and know what is in them. That will also give you code-completion for
PyQt.
Apart from that, it is usually not a good practice to use from foo
import *. You'll be importing everything inside your namespace and you
wouldn't know which is coming from where. Moreover you might have name
clashes that mask each other. Though it is unlikely with PyQt, still
I'd suggest you get used to from PyQt4 import QtGui, QtCore and
reference classes like QtGui.QMainWindow.

Related

How to properly wrap a c++ library which uses qt with shiboken2?

I have seen the FAQ https://wiki.qt.io/Qt_for_Python#Frequently_Asked_Questions which states
Take into account that if you want to generate bindings for a Qt/C++
project, the linking to the Qt shared libraries will be missing, and
you will need to do this by hand. We recommend to build PySide2 from
scratch to have everything properly linked.
Suppose you want to use shiboken2 to wrap a c++ library which itself uses qt and it even uses qt classes in its interface. In the python world you should be able to
pip install PySide2 my_cpp_lib
and afterwards python scripts shall be able to
import my_cpp_lib
from PySide2.QtCore import QObject
my_cool_object = QObject()
my_cpp_lib.my_cool_api(my_cool_object)
It is pretty unclear to me how to achieve that setup. From the FAQ I deduce that it would be good to compile PySide2 from source in this case (because I want to use shiboken2_generator to wrap my_cpp_lib). However, I still want to be compatible to the standard PySide2 package (of course there will be a version dependency between my_cpp_lib and PySide2).
Is linking against the QT shared object/dll of PySide2 a bad idea? If so, why? what would be better instead?
If the qt library should be packaged together with the my_cpp_lib python package, then how is it possible to still use PySide without conflicts (because there are essential two different shared objects)?

Eclipse, PyDev, PySide, importing, and parsing

I am working in Eclipse but running my code in Nuke. Nuke uses PySide, but it's built into Nuke so Eclipse can't parse it. I cannot install PySide in my environment (VFX studio rules) but I do have PyQt4. So I can change my import from PySide to PyQt4 and it parses correctly in Eclipse - but it will error when loading Nuke. So what I need is a way to get Eclipse/PyDev to use PyQt4 while Nuke uses PySide. I thought perhaps I could use PyDev's String Substitution scheme but either it doesn't do what I want or I'm not using it right. Any help is greatly appreciated!
Den
Use Rob's qtshim.py.
You'll find it here: https://github.com/rgalanakis/practicalmayapython/blob/master/src/chapter5/qtshim.py
Import QtCore, QtGui etc. From qtshim instead of PySide or PyQt. Code written with this will work for both environments.
I use my own version of something like this to work with PyQt and PySide.
Hope that was useful.

Sublime Text 2. Autocomplete python `from`

I am using SublimeRope plugin. When I am typing from foo.b it displays the autocomplete dialog with random crap but what I am really looking for is to recognize bar module inside the foo package. However if I type from foo import b it immediately suggest me to import bar as a module. Which means Rope "knows" about that module. How can I configure my Sublime to help me suggest the imports when from foo.b ?
I am doing projects with django so the real example it wont me to autocomplete from django.contrib. but if I type from django.contrib.auth.models import U it suggest me to import user.
You should definitely be using SublimeJEDI for Python autocompletion! There's no way around Jedi awesomeness.
This is just a Sublime Plugin for the Jedi library (which is definitely better than Rope, but I'm biased because I'm the author).
Just adding to what other have said sublimecodeintel can help you with this. However to get it working with Django as you would like you have to add a configuration file pointing to django to your project. The instructions for how to do this are on the github page linked above. You'll add something similar to this:
{
"Django":{
"django":'/Users/bin/python2.7/site-packages/django'
},
}
Have you checked out SublimeCodeIntel? It's available through Package Control, and has this functionality. The initial indexing of your packages may take some time, but once it's all set (you may need to restart Sublime once or twice to get everything loaded) it works like a charm.

Inconsistency between IDLE/PythonWin during module imports

I have been fumbling around between IDLE/PythonWin and even Aptana Studio 3 trying to get some consistency regarding importing modules. The modules I have been using lately are wx from wxPython and the arcpy module. IDLE will let me import arcpy, but not wx. PythonWin will let me import wx, but not arcpy.
When I do sys.executable in IDLE I get "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonwin\Pythonwin.exe"
When I do sys.executable in PythonWin I get "C:\Python27\pythonw.exe"
Additionally, I am wondering if I am using different interpreters, how to set them all to the same one, and which one to use.
I have been learning and using Python for a little over half a year now and am at the point where I would really like to have these kinds of issues under control.
edit: lesson learned years later: use pycharm and let it keep your environments separate for you! lol
The problem is that ArcGIS comes with its own specific Python bundled with the software and you have installed a normal distribution into "C:\Python27\". I would try removing the latter and reinstalling wxPython. I'm guessing this IDLE of which you speak is actually embedded in ArcGIS rather than being the normal IDLE.
To be more clear, when you originally installed wx, it saw the Python in "C:\Python27\" and installed in that location. If you can't get wx to install to the GIS location, there may be a way to fake it by just copying the wx folder from C:\Python27\ and putting it in ArcGIS. They should both be in something like "C:\Python27\Lib\site-packages\wx-2.9.3-msw" (depending on version) and there's also a wx.pth file you'll need to copy from ""C:\Python27\Lib\site-packages" to the same basic location in the GIS directory.
EDIT: I also found the following links that might address your issue:
http://www.scoop.it/t/arcpy/p/1759717424/custom-wxpython-gui-s-an-approach-for-arcgis-10-1-arcgis-resource-center
http://forums.arcgis.com/threads/41809-wxPython-hooked-to-arcmap
wxPython and ARCGIS
It sounds like you have to add wxPython as an add-in.

PyQt4 names showing as undefined in eclipse, but it runs fine

I am using Eclipse 3.7.1 with the latest PyDev add-in for Python coding. I am using PyQt4. At the top of my file I have:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
In addition, I have the PyQt4 tree included in the Project Explorer listing. However, eclipse still thinks the names like QMainWindow are undefined. The code runs fine. How may I get eclipse to recognize those names.
Thanks
PyQt is actually a wrapping of C++ Qt libraries. So they are not .py files and PyDev can't analyze them to get what is in them. You need to add PyQt4 in the Forced Builtins tab, so that PyDev can use a Python shell to "look into" those libraries and know what is in them. That will also give you code-completion for PyQt.
Apart from that, it is usually not a good practice to use from foo import *. You'll be importing everything inside your namespace and you wouldn't know which is coming from where. Moreover you might have name clashes that mask each other. Though it is unlikely with PyQt, still I'd suggest you get used to from PyQt4 import QtGui, QtCore and reference classes like QtGui.QMainWindow.
it happens sometimes that PyDev lose its mind...
If restarting Eclipse don't do the trick, consider doing this:
Click on the "Apply" button and select your python interpreter. That should force Eclipse to recover existing libraries.

Categories