Unable to Open File
-
Hello Guys I am currently working on the project where I have created a ui file using Qt Designer and I am trying to Load that particular UI file but it is giving me an error:
Traceback (most recent call last):
File "/home/xanthas/Desktop/ATE/ATE_SOFTWARE_V3/v2_main.py", line 233, in Fixed_Wing_connect
ATE_OBJ_Fixed_Wing=Fixed_Wing_UI()
File "/home/xanthas/Desktop/ATE/ATE_SOFTWARE_V3/v2_main.py", line 130, in init
loadUi('Fixed_Wing.ui',self)
File "/home/xanthas/.local/lib/python3.8/site-packages/PyQt5/uic/init.py", line 241, in loadUi
return DynamicUILoader(package).loadUi(uifile, baseinstance, resource_suffix)
File "/home/xanthas/.local/lib/python3.8/site-packages/PyQt5/uic/Loader/loader.py", line 66, in loadUi
return self.parse(filename, resource_suffix)
File "/home/xanthas/.local/lib/python3.8/site-packages/PyQt5/uic/uiparser.py", line 1020, in parse
document = parse(filename)
File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1202, in parse
tree.parse(source, parser)
File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 584, in parse
source = open(source, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'Fixed_Wing.ui'But the file is in the same folder as that of the main file. What could be the issue?
wrote on 26 Feb 2024, 12:32 last edited by@vidyul
You are using a relative pathname. That means it will only be found if the current directory is where the file is. That depends on how you started the program from where. I don't know whether Python changes the current directory to where the invoked.py
file is located. You can check this and/or use a full path to the file. -
@vidyul
You are using a relative pathname. That means it will only be found if the current directory is where the file is. That depends on how you started the program from where. I don't know whether Python changes the current directory to where the invoked.py
file is located. You can check this and/or use a full path to the file. -
@JonB All my files are in the same directory as I mentioned above then too it is not opening.
wrote on 27 Feb 2024, 08:44 last edited by JonB@vidyul
I don't see how that addresses the possible issue.FileNotFoundError: [Errno 2] No such file or directory: 'Fixed_Wing.ui'
Did you at least take the 10 seconds to try passing the full path to
Fixed_Wing.ui
inloadUi('.../Fixed_Wing.ui',self)
, then we would be sure? -
@vidyul
I don't see how that addresses the possible issue.FileNotFoundError: [Errno 2] No such file or directory: 'Fixed_Wing.ui'
Did you at least take the 10 seconds to try passing the full path to
Fixed_Wing.ui
inloadUi('.../Fixed_Wing.ui',self)
, then we would be sure?wrote on 27 Feb 2024, 09:02 last edited by@JonB Yes I tried that too. So, what I have figured out is when I am trying to run the main file from vs code then only it gives me an error. Otherwise when I try to run through the terminal, I don't need to specify even the path or directory. Is it the issue with VS Code then?
-
@JonB Yes I tried that too. So, what I have figured out is when I am trying to run the main file from vs code then only it gives me an error. Otherwise when I try to run through the terminal, I don't need to specify even the path or directory. Is it the issue with VS Code then?
wrote on 27 Feb 2024, 09:23 last edited by JonB@vidyul
vscode should be an environment for developing code. I cannot imagine how it could alter the behaviour ofloadUi('Fixed_Wing.ui',self)
or lead to errorFileNotFoundError: [Errno 2] No such file or directory: 'Fixed_Wing.ui'
, especially if you use full path.Otherwise when I try to run through the terminal, I don't need to specify even the path or directory.
How could your code, run from terminal or not, possibly know to call
loadUi('Fixed_Wing.ui',self)
if you never tell it to load a file namedFixed_Wing.ui
? Or do you mean, you do tell it to load it but don't need to pass a path to it? Your statement is unclear.I don't know what is going on in your code or the way you invoke it. Let's start with: are you indeed intending to call
loadUI()
at runtime or are you intending to runuic
(or whatever for Python) at build time to generate a.py
file from your.ui
file? These are two different approaches for using.ui
file from Designer.If you are intending to use
loadUI()
, could you please show the actual statement with the full path in it. -
@vidyul
vscode should be an environment for developing code. I cannot imagine how it could alter the behaviour ofloadUi('Fixed_Wing.ui',self)
or lead to errorFileNotFoundError: [Errno 2] No such file or directory: 'Fixed_Wing.ui'
, especially if you use full path.Otherwise when I try to run through the terminal, I don't need to specify even the path or directory.
How could your code, run from terminal or not, possibly know to call
loadUi('Fixed_Wing.ui',self)
if you never tell it to load a file namedFixed_Wing.ui
? Or do you mean, you do tell it to load it but don't need to pass a path to it? Your statement is unclear.I don't know what is going on in your code or the way you invoke it. Let's start with: are you indeed intending to call
loadUI()
at runtime or are you intending to runuic
(or whatever for Python) at build time to generate a.py
file from your.ui
file? These are two different approaches for using.ui
file from Designer.If you are intending to use
loadUI()
, could you please show the actual statement with the full path in it. -
@JonB Here is the screenshot of the error but it runs fine through terminal, the same code (loads the UI file).
wrote on 27 Feb 2024, 12:37 last edited by JonB@vidyul said in Unable to Open File:
but it runs fine through terminal, the same code (loads the UI file).
I know this. You already said it. And I previously said why this could be an issue.
@JonB said in Unable to Open File:
If you are intending to use
loadUI()
, could you please show the actual statement with the full path in it.Can you please read and follow instructions if you want help (at least my help). This really isn't too difficult, I already told you what the issue is likely to be. Just wasting time if you can't or won't follow the suggestion/instruction. When you have corrected it, copy & paste the line of code with
loadUI()
in it, not screenshot. -
@vidyul said in Unable to Open File:
but it runs fine through terminal, the same code (loads the UI file).
I know this. You already said it. And I previously said why this could be an issue.
@JonB said in Unable to Open File:
If you are intending to use
loadUI()
, could you please show the actual statement with the full path in it.Can you please read and follow instructions if you want help (at least my help). This really isn't too difficult, I already told you what the issue is likely to be. Just wasting time if you can't or won't follow the suggestion/instruction. When you have corrected it, copy & paste the line of code with
loadUI()
in it, not screenshot.wrote on 28 Feb 2024, 04:11 last edited by@JonB your last statement seems to be rude here. What did you mean by 'atleast my help'. Maybe I miss interpret your last suggestion but this is not the way you can respond. Ofcourse we are here to help each other out isn't it?
-
@JonB your last statement seems to be rude here. What did you mean by 'atleast my help'. Maybe I miss interpret your last suggestion but this is not the way you can respond. Ofcourse we are here to help each other out isn't it?
wrote on 28 Feb 2024, 09:28 last edited by JonB@vidyul
It expressed my frustration. I have explained that behaviour might differ between command line and vscode depending on what the current directory is. I said you must use a full path to see if that is the case. You said you did and it still does not work, so I need to see what you specified for a "full path" and hence asked:If you are intending to use
loadUI()
, could you please show the actual statement with the full path in it.You can see that italicised "with the full path in it". Because that is what we need to see.
You responded with (a screenshot of) code which still uses a relative path. Despite my saying that could be the problem. It seems to me that is "rude here", like you didn't bother to read my responses. If "we are here to help each other out" then you have to act on what someone responds or is asking for. "but this is not the way you can respond" applies equally to you ignoring what is asked for in your response.
So now, for the third time, I ask again: can you copy and paste the
loadUI()
you try to use which does not work and has a full path in it? The "at least my help" means: if I am to help you need to reply with that information; if you don't, that's fine, but you will need help from someone other than me. -
@vidyul
It expressed my frustration. I have explained that behaviour might differ between command line and vscode depending on what the current directory is. I said you must use a full path to see if that is the case. You said you did and it still does not work, so I need to see what you specified for a "full path" and hence asked:If you are intending to use
loadUI()
, could you please show the actual statement with the full path in it.You can see that italicised "with the full path in it". Because that is what we need to see.
You responded with (a screenshot of) code which still uses a relative path. Despite my saying that could be the problem. It seems to me that is "rude here", like you didn't bother to read my responses. If "we are here to help each other out" then you have to act on what someone responds or is asking for. "but this is not the way you can respond" applies equally to you ignoring what is asked for in your response.
So now, for the third time, I ask again: can you copy and paste the
loadUI()
you try to use which does not work and has a full path in it? The "at least my help" means: if I am to help you need to reply with that information; if you don't, that's fine, but you will need help from someone other than me. -