NameError: global name 'QString' is not defined
I was trying to use TIM for the first time and I get the following error when I tried launching TIM by running 'tim.py'. (Before that, I got an error due to no 'pint' module, which I overcame by installing that module.)
File "C:\Anaconda\lib\json\decoder.py", line 380, in raw_decode
obj, end = self.scan_once(s, idx)
File "timgui\colorbar_and_scale.py", line 406, in objectHookColorBar
cb.valueScale = d['values']
File "timgui\colorbar_and_scale.py", line 178, in setValueScale
if isinstance(v,(str,np.string_,QString)):
NameError: global name 'QString' is not defined
Comments (18)
-
repo owner -
reporter Hi. I am using Python 2. Regarding the output from the suggested commands, this is what I get:
sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0) import PyQt4.QtCore PyQt4.QtCore.QString Traceback (most recent call last): File "<ipython-input-2-7ea3631772af>", line 1, in <module> PyQt4.QtCore.QString AttributeError: 'module' object has no attribute 'QString'
-
repo owner Hi,
I have not seen this before, but from the look of it I think it may have something to do with the PyQt4 that comes with the your Python setup. I am guessing you are using anaconda or ipython set of tools? Which I don't have experience with.
Here is a link from a quick search. http://stackoverflow.com/a/22333369/2368167
I can try to modify TIM to make it work on your environment, but I will need help as how you setup your Python/PyQt/IPython/Anaconda etc on your machine.
Let me know what you think, thanks! In the mean while I will take a look to learn about those IPython side of things.
Regards, Angus
-
repo owner Hi,
Could you try this on your system?
Modify the source file of tim.py to the following content:
#! python distutils installer will modify this line (for *unix) """ Copyright 2013, 2014 University of Auckland. This file is part of TIM (Tim Isn't Mulgraph). TIM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. TIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with TIM. If not, see <http://www.gnu.org/licenses/>. """ if __name__ == '__main__': import sip sip.setapi('QString', 1) # overwrite version info with detailed git desc if git/repo available import timgui.info from get_version_info import getGitDesc v = getGitDesc() if v: timgui.info.long_version = v # this will trigger initialisation of logging module import timgui.log from PyQt4.QtGui import QApplication,QIcon import sys app = QApplication(sys.argv) app.setOrganizationName("University of Auckland") app.setOrganizationDomain("auckland.ac.nz") app.setApplicationName("Tim isn't Mulgraph") app.setWindowIcon(QIcon(":/rabbit_large.png")) from timgui.ui_main_window import MainWindow tim = MainWindow() tim.show() app.exec_()
-
reporter Hi Angus. I tried the option you suggested, but I get the following error:
sip.setapi('QString', 1) ValueError: API 'QString' has already been set to version 2
Based on the above error, I tried changing the above command to sip.setapi('QString', 2), but it throws the following commands:
INFO:root:Tim Isn't Mulgraph 0.6.7 -INFO Tim Isn't Mulgraph 0.6.7 WARNING:pint.util:Redefining 'year' (<class 'pint.definitions.UnitDefinition'>) -WARNING Redefining 'year' (<class 'pint.definitions.UnitDefinition'>) WARNING:pint.util:Redefining 'darcy' (<class 'pint.definitions.UnitDefinition'>) -WARNING Redefining 'darcy' (<class 'pint.definitions.UnitDefinition'>) INFO:root:User settings file C:\AppData\Roaming\TIM\arrow_scales.json does not exist -INFO User settings file C:\AppData\Roaming\TIM\arrow_scales.json does not exist INFO:root:Reading file timgui\arrow_scales.json. -INFO Reading file timgui\arrow_scales.json. INFO:root:User settings file C:\AppData\Roaming\TIM\colorbars.json does not exist -INFO User settings file C:\AppData\Roaming\TIM\colorbars.json does not exist INFO:root:Reading file timgui\colorbars.json. -INFO Reading file timgui\colorbars.json.
After the above commands are displayed, it throws an error as shown below:
File "timgui\colorbar_and_scale.py", line 178, in setValueScale if isinstance(v,(str,np.string_,QString)): NameError: global name 'QString' is not defined
-
repo owner Hi,
Are you using IPython? Is IPython launched with --gui=qt or --matplotlib=qt?
If indeed IPython, I think I know the cause now. PyQt has two API versions, v1 and v2. TIM at the moment uses v1 API in the codes, which is required to use QString and QVariant. Your environment uses v2 API.
The IPython you are using to launch TIM must have pre-loaded PyQt with v2 API. Hence the modification I sent you won't work. Once PyQt api is set, it can not be changed.
One possible solution is to launch IPython without loading PyQt before it starts TIM, giving TIM a change to dictate the use of v1 API. I have never used IPython before, but I will poke around and see what I can learn.
It would be nice if you could let me know more about your Python environment: - OS (windows?) - IPython? - how did you install PyQt4, Numpy, matplotlib etc? - or did you use any scientific stack libraries? (eg. anaconda)
Another solution is to use the packaged version (https://bitbucket.org/angusyeh/tim/downloads) which includes its own python environment and dependency.
I will also upload some examples so you can load something into TIM when you try it. Give me a few days to do it.
Regards, Angus
-
reporter ?Hi Angus. I am using Anaconda IDE, which has two consoles, IPython console and a second one that's just called console. I have added three images that answer your questions and more about the Anaconda IDE preferences:
-
repo owner Thanks for the info. It's very useful!
Could you have a quick try to start TIM using the normal "Console" with the PyQt API set to # 1?
Thanks~
Regards, Angus
-
reporter I do see a gui pop out after running (without using the sip.setapi('QString', 2) command you suggested earlier) as shown below. I also receive some messages on the console that are also shown below. The process of running this on the plain 'console' was not very convenient (it can't be run with F5), so if there's some workaround to run this using IPython console as well then that will be better. If you could do that and add some examples to try TIM then that will be quite good.
'import sitecustomize' failed; use -v for traceback -INFO Tim Isn't Mulgraph 0.6.7 -WARNING Redefining 'year' (<class 'pint.definitions.UnitDefinition'>) -WARNING Redefining 'darcy' (<class 'pint.definitions.UnitDefinition'>) -INFO User settings file C:\AppData\Roaming\TIM\arrow_scales.json does not exist -INFO Reading file C:\Desktop\TIM-master\timgui\arrow_scales.json. -INFO User settings file C:\AppData\Roaming\TIM\colorbars.json does not exist -INFO Reading file C:\Desktop\TIM-master\timgui\colorbars.json. -INFO User settings file C:AppData/Roaming/TIM/plot_with_elevation.json does not exist -INFO User settings file C:/AppData/Roaming/TIM/time_history_plot.json does not exist -INFO user settings not found, skip loading user commands. libpng warning: iCCP: known incorrect sRGB profile
Thanks and regards.
-
repo owner Thanks for checking this. I will have a look at Anaconda IDE myself and see what's going on.
Also I am just curious, are you intending to use TIM as stand alone GUI? or use its components?
Regards, Angus
-
reporter Does the above gui seem OK to you? There are some messages that suggest failure to load some settings, so I was not sure if the gui I was able to get is alright.
My purpose of using TIM was to use it as a tool to process the mesh for Tough. I am not yet aware about all the components of TIM...
Regards,
-
repo owner Hi,
Yes, that looks normal as designed.
I will have some examples coming.
Regards, Angus
-
reporter Hi...just checking if you followed-up on examples as discussed. Thanks.
-
repo owner Hi,
Sorry I was away from work for quite a few days. I am back working on it now.
Regards, Angus
-
reporter No problem. I just thought to ask if that's still on your mind...but, you can take your time, I am not in a hurry. Thanks for your support.
-
repo owner Hi,
I have just uploaded a small example. A quick start guide can be found here.
The ex1 example contains these files:
-
gex1.dat is the geometry file.
-
ex1.dat is the input file of natural state
-
ex1.listing is the output file of natural state
-
ex2.dat is the input file of production (trasient/history) run
-
ex2.listing is the output file of production run
-
ex1_create.py and ex2_create.py are python/PyTOUGH scripts used to create these examples.
Let me know if these works as a quick example. In the future I will tidy this up (along with other examples) and create a tutorial that users can follow.
Regards, Angus
-
-
reporter Thanks a lot. I will take a look when I can.
Thanks again, and regards.
-
repo owner - edited description
-
assigned issue to
- marked as enhancement
- marked as minor
Change issue to enhancement.
Should investigate longer term solution to deal with different PyQt (SIP API issue) environment.
- Log in to comment
Hi,
Are you using Python 2 or Python 3?
Also it seems you are using anaconda, which I am not familiar with, is PyQt4 you are using part of the anaconda stack?
if possible, let me know what it looks like when you run these commands in python:
Thanks for reporting the issue.
Angus