'qt5' is currently running !

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
abghrnjd
Posts: 43
Joined: Tue Dec 22, 2020 12:02 pm

Re: 'qt5' is currently running !

Post by abghrnjd »

Please post your script, as probably the problem reside here.

A side note, try to use a "portable build" on Windows this way it is isolated from the library installed in the system, and usually this is a good thing, as I see from your data that you are using python 3.8.6 and it seems a bit old (now python is 3.10.x).

Regards
Carlo D.
My code is too long. I added 2 functions (as 2 files) to this folder

Code: Select all

C:\Program Files\FreeCAD 0.19\bin\Lib 
Can I do this in "portable build"?

I was using python 3.10 when the error happened I decided to use lower version. I guess this is not the problem because Freecad seems to have its own python version and there is no need to install python on the computer to run a macro.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: 'qt5' is currently running !

Post by onekk »

Probably you are messing up with python versions.

portable builds are here:

https://github.com/FreeCAD/FreeCAD/rele ... able-1.zip

Usually it need to simply unzip the file in a directory and run from here. this way FC is isolated from system.

Sadly I've not found a relevant page were the installation of portable build is explained.

Usually a script could reside in every directory you want, it suffice to load it in FC and if the file is named *.py or *.FCMacro it will open in the "Macro editor".

But if the script is big I don't know, you could add the path to the "internal python" using:

Code: Select all

MODULE_PATH = u"/whatever_is_your_path/"

DBG_LOAD = True

if not MODULE_PATH in sys.path:
    if DBG_LOAD is True:
        print("no module path")
    sys.path.insert(-1,MODULE_PATH)
else:
    if DBG_LOAD is True:    
        print("module path is present")
        

if DBG_LOAD is True:    
    print(sys.path)
And the directory where your module reside is added to the sys.path (for the running instance if you use a "portable build")

This way you are not polluting FC installation.

Said so it is difficult to debug problem without code.

Hope it helps.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
abghrnjd
Posts: 43
Joined: Tue Dec 22, 2020 12:02 pm

Re: 'qt5' is currently running !

Post by abghrnjd »

onekk wrote: Sat Jul 23, 2022 8:10 am And the directory where your module reside is added to the sys.path (for the running instance if you use a "portable build")
This way you are not polluting FC installation.
Said so it is difficult to debug problem without code.
Hope it helps.
Regards
Carlo D.
I downloaded the portable build. Didn't help. The same problem.
But How did it know where my macro folder is located? Should I uninstall the regular version?
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: 'qt5' is currently running !

Post by onekk »

Macro folder is set in the Macro menu item where you could specify macro directories, now I'm on mobile so ni link from wiki or forum post but probably a simple search will gave results.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: 'qt5' is currently running !

Post by heda »

as said, this is with 99.9% probability something on your computer (configs/scripts), not so much related to fc as such, other than how you have installed things (read - anything related to python, not just fc).


"I downloaded the portable build. Didn't help. The same problem.
But How did it know where my macro folder is located? Should I uninstall the regular version?"

"was working on 0.18 version"

"upgraded to 0.20 version. I get this error: "

"OS: Windows 10 Version 2009
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24276 (Git)
Build type: Release
Branch: releases/FreeCAD-0-19"

"I was using python 3.10 when the error happened"


time-out and take a deep breath.
you seem to be all over the place, version 18-20, running py3.10 separately?
random attempts (although you have found the mpl-backend knob)
seems to have gotten you nowhere so far (unless you managed to make it by now...)

anyhow, no, one does not run macros by an external python, especially not a 3.10, macros are best run in fc's bundled python (what python that is bundled depends on release).

yes, fc keeps the macros in a folder that is not affected by changing versions of fc, so that is how it finds it back.

a bit surprising if you got this by switching from v18 to v20, afaik also win-builds on v18 is qt5, so why should mpl go on strike on qt4 with v20 but not v18? does the v18 still work with the macro?

let's see if this can be sorted out:
a) please do the "about info" from your fc 18 that worked, also how you installed it
b) please describe what you have done as external installs on python, and how you did those installs (and what libs you have in those).
c) list all the add-ons that you have on your box, workbenches and macros (and if this is different from when it worked to when it started not to work)
d) make a log and post that - Start_up_and_Configuration


once again, you have somehow managed to break your own installation and there is some dirt on your computer - that only you can find & wipe out to make it work again - the only thing we can do is to provide some hints.

if you don't want to go through the steps above, well, uninstall any python that you have on your computer, completely wipe the configuration folders for both freecad and matplotlib (they are typically folders starting with a "." somewhere in your user-space - you can find exactly where in documentation for mpl or fc, might not hurt though in your case to also make searches on complete hd - maybe you have things in unexpected places...)

just make sure that you keep versions around in a safe space for whatever you have written as macros, otherwise those will be lost forever...

fc has clearly started qt5, so somewhere after fc is running there is a config that mpl is looking into or an import of qt4 that is triggered. this could very well be something changed in mpl as well, making it incompatible, but that is quite far-fetched, since it was years back the transition from qt4-qt5 as major framework happened in mpl (so anything related to that in mpl is very likely to have been fully sorted out for say the last 5+ years)
abghrnjd
Posts: 43
Joined: Tue Dec 22, 2020 12:02 pm

Re: 'qt5' is currently running !

Post by abghrnjd »

Thank you.
I guess some thing is triggering qt4. Could it be related to pyside?

I will send suspucious parts of code here asap.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: 'qt5' is currently running !

Post by onekk »

The point is different, I think.

In heda post he has some doubt about what version of FC you are using.

You said you have used many, and no one was make your "code" works.

Here some general considerations:

1) use 0.20 as it is the latest stable and will have updates in the future via "point releases" so if bugs are arising, most probably they will be fixed. 0.19 is old stabel and won't receive bug fixes anymore.

2) as you could have fiddled with different versions, try to find where the configuration files for FC resides and delete this user directory to have a "clean user configuration" that could happen if you mix different versions with some caveats.

3) in which way you are running "code", the normal way is to load the code in the internal "Macro Editor" and run it from here.
simply load the ".py" or a ".FCMacro" file using the menu item file -- Open and it will be opened in a "Macro Editor" window on FC.
Other ways are problematics, it is not impossible to make it run, but using "FreeCAD as a library" is not the "main way" to use FreeCAD and is not the most documented and supported one

4) without code is difficult to tell,

5) as the problem could reside even in some "environment variables" as Qt read also these so you should check if maybe some "old installations" has left some environment variables set around, in Windows is easy to forgot that you maybe have set and "environment variable" maybe some time ago and left it here, as it is not immediately visible.

After some time, I think that is a good way to answer these questions, so people that would help you have a clear idea of "what is happening".

For point 1) (You have already done that, so it is not difficult) use the the instructions you will find under IMPORTANT: at the link https://forum.freecadweb.org/viewtopic.php?f=3&t=2264 and please stay with 0.20.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
abghrnjd
Posts: 43
Joined: Tue Dec 22, 2020 12:02 pm

Re: 'qt5' is currently running !

Post by abghrnjd »

onekk wrote: Mon Jul 25, 2022 1:15 pm Carlo D.
My code:

Code: Select all

import numpy as np
from numpy import random
import FreeCAD
import PartDesignGui
from PySide import QtGui
import EvalMacro
#-------------Clear----------------------
mw=Gui.getMainWindow()
mw.findChild(QtGui.QPlainTextEdit,"Python console").clear()
mw.findChild(QtGui.QTextEdit,"Report view").clear()

#-------------GA Functions---------------
def popGen(popSize,Var_limit,N_var):
...GA population func....
 return  pop

def COST(pop):
...  EvalMacro() ...
  return cost
###### GA Parameters
...

while np.min(cost)>50:
...GA code...
print("Final Solution:",np.round(pop[0,:],2));
I have 2 functions. The error refers to THIS function:

Code: Select all

def EvalMechanism(L1,L2,L3,L4,NumberOfsteps):
 import FreeCAD as App
 import FreeCADGui as Gui 
 import PartDesignGui,Show
 import time,math
 import a2p_solversystem as a2p_solver
 import a2plib
 import numpy as np
 import matplotlib.pyplot as plt
 #matplotlib.use('Qt5Agg')
 plt.switch_backend('Qt5Agg')
 from a2p_importpart import updateImportedParts
 from PySide import QtGui
 import LinkMacro
#----------------Part Generation----------
 print("Link Lenght:","%.2f"%L1,"%.2f"%L2,"%.2f"%L3,"%.2f"%L4)
 LinkMacro.LinkGen(L1,'Link_0')
 LinkMacro.LinkGen(L2,'Link_1')
 LinkMacro.LinkGen(L3,'Link_2')
 LinkMacro.LinkGen(L4,'Link_3')
 App.open(u"D:/Saved Files/FreeCAD/RRRR/Link_0.FCStd")
 App.open(u"D:/Saved Files/FreeCAD/RRRR/Link_1.FCStd")
 App.open(u"D:/Saved Files/FreeCAD/RRRR/Link_2.FCStd")
 App.open(u"D:/Saved Files/FreeCAD/RRRR/Link_3.FCStd")
 App.open(u"D:/Saved Files/FreeCAD/RRRR/test.FCStd")
 print("Parts and Assembly are created!")
# App.ActiveDocument=App.getDocument("test")
# Gui.ActiveDocument=Gui.getDocument("test")
 Gui.activateWorkbench("A2plusWorkbench")
 a2plib.setAutoSolve(False)
 updateImportedParts(App.ActiveDocument)
 a2plib.setAutoSolve(True)
#-----------Variables---------
 i=0;StepAngle=0;
 #NumberOfsteps=10;
 timeout=.0001;current_orientation=0;error=0;Angle_diff=np.zeros(NumberOfsteps);
 theta_1=5;theta_2=175;Delta=theta_2-theta_1;cm = 1/2.54;try2conv=0;
 Link2Angle=np.zeros(NumberOfsteps);Link2PosX=np.zeros(NumberOfsteps);Link2PosY=np.zeros(NumberOfsteps);
 Link2PosX_vertex=np.zeros(NumberOfsteps);Link2PosY_vertex=np.zeros(NumberOfsteps);
 Angle_ideal=np.linspace(10, 30, num=NumberOfsteps)
 steps2reach=0;converging=True
 document = App.activeDocument()
 App.setActiveDocument("test")
 App.ActiveDocument=App.getDocument("test")
 Gui.ActiveDocument=Gui.getDocument("test")
#-----------------------------------------------------------------
 Gui.activeDocument().activeView().viewTop()
 success = a2p_solver.solveConstraints(document,showFailMessage=False)
 if success == False:
  print("\n Mechanism is inconsistance at the Beginning!")
  converging=False
  #MechanismCOST=10**5;
 elif success is None:
  Gui.SendMsgToActiveView("ViewFit");Gui.updateGui();
  current_orientation=math.degrees(App.ActiveDocument.b_Link_3_001_.Placement.Rotation.Angle);#percentage
  while (steps2reach<NumberOfsteps and converging):
   steps2reach=steps2reach+1;
   print("Step Number:",steps2reach);
   pos=App.Vector(0,0,0);
   ori=App.Rotation(App.Vector(0,0,-1),theta_1+StepAngle);
   try2conv=0;
   while ( abs(current_orientation-(theta_1+StepAngle) ))>=1:
    App.getDocument("test").b_Link_3_001_.Placement=App.Placement(pos,ori,App.Vector(0,0,0));
    a2p_solver.solveConstraints(document);
    App.ActiveDocument.recompute();Gui.updateGui();
    current_orientation=math.degrees(App.ActiveDocument.b_Link_3_001_.Placement.Rotation.Angle);#percentage
    error=100*abs(current_orientation-(theta_1+StepAngle))/(theta_1+StepAngle)
    print("%.2f" %current_orientation,"%.2f" %(theta_1+StepAngle)," error:","%.2f" %error,"%" )
    try2conv=try2conv+1; #print("try: ",try2conv)
    success = a2p_solver.solveConstraints(document,showFailMessage=False)
    if success == False:
      print("\n Mechanism is inconsistance! @try:",try2conv)
      try2conv=0;
      converging=False
      break
    elif try2conv>=25:
      print("\n Mechanism is Locked! @try:",try2conv)   
      try2conv=0;
      converging=False
      break
    elif success is None: #when it success converging to new step
      converging=True
      print("Converging... @try:",try2conv)
      Link2Angle[steps2reach-1]=math.degrees(App.ActiveDocument.b_Link_2_001_.Placement.Rotation.Angle);
      Link2PosX[steps2reach-1]=App.ActiveDocument.b_Link_2_001_.Placement.Base[0];
      Link2PosY[steps2reach-1]=App.ActiveDocument.b_Link_2_001_.Placement.Base[1];
   StepAngle=StepAngle+(Delta/(NumberOfsteps-1));
  #time.sleep(1)
  #steps2reach=0;
  #StepAngle=0;
 if converging: #All steps are converged.
  Angle_diff=np.sqrt((Link2Angle-Angle_ideal)**2);
  CostVar=np.var(np.abs(Link2Angle));
  MechanismCOST=np.sum(Angle_diff)+CostVar;
  #------------------PLotting-----------------
  # plt.close()
  # plt.figure(figsize=(12,5));
  # plt.subplot(131);plt.plot(Link2PosX,Link2PosY,'r');plt.title('Path',fontsize=12); plt.xlabel('x');plt.ylabel('y'); plt.grid(True);# x-y
  # plt.subplot(132);plt.plot(Link2Angle);plt.plot(Angle_ideal,"*");plt.title('Angle',fontsize=12);plt.xlabel('step');plt.ylabel('Degrees'); #Angle
  # plt.subplot(133);plt.plot(Angle_diff,"k");plt.title('diff',fontsize=12); plt.xlabel('step');plt.ylabel('Angle_diff'); #cost
  # plt.axis('equal');plt.show()
 else:
  MechanismCOST=10**6;
  
 #steps2reach=0;
 #StepAngle=0;
 App.closeDocument("Link_0");App.closeDocument("Link_1");App.closeDocument("Link_2");App.closeDocument("Link_3");
 App.getDocument("test").save();App.closeDocument("test");Gui.SendMsgToActiveView("Save")
 return MechanismCOST; ;
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: 'qt5' is currently running !

Post by onekk »

why imports are placed in a method?

Usually this is done rarely when there are some conditions due to different os but in your case it is an error that could cause unexpected behaviour, plus a partial code is not telling nothing about what you are missing.

You could attach files like images or simply dragging and dropping in the edit message window.

You are telling nothing about other questions, especially point 3.


Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: 'qt5' is currently running !

Post by heda »

why not just try Plot_Workbench and cross your fingers that it works for you...

happened to try on 0.19, but the write-up on wiki did not work
however below worked...

Code: Select all

import freecad.plot
plt = freecad.plot.freecad_backend.plt
someone else will have to try on 0.20 if the instructions are bogus there as well...
Post Reply