When using the qtmoden library with python.
It works fine when running the code in VS Code.
But after using pyinstaller, it doens't anymore. When opening teh generated .exe file, it states that it does not have access to files located in - C:\Users\MyUsername\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\qtmodern\resources
When running the .exe aplication it errors stating:
Traceback (most recent call last):
File "my_filename.py", line 262, in (this number differs depending on my app/code)
File "qtmodern\styles.py", line 70, in dark
File "qtmodern\styles.py", line 23, in _apply_base_theme
FileNotFoundError: [Errno 2] No such file or directory: " 'C:\sers\MyName\AppData\Local\Temp_MEI166802\qtmodern\resources/styles.qss'
[36020] failed to execute script my_filename
Anybody any idea how to get this fixed?
How to make sure pyinstaller also takes these 2 stypes.py files into account?
I tried adding data with pyinstaller via the --add--data command and including paths with --paths command, But the error message stays the exact same.
Related
I am trying to develop an Mixed Integer Linear Programming (MILP) optimization tool with Excel and Python. Pyomo with GLPK solver are being used for MILP optimization. Python program reads inputs from the excel file and write output to an excel file. I used Pyinstaller to create exe file. The program works when exe file is opened as expected.
The Problem -
I want to trigger the exe file using VBA Macros from the excel file. When the exe file is triggered from the VBA Macro using the Shell() command, the program gives following error - "ValueError: Failed to set executable for solver glpk. File with name=glpk-4.65\w64\glpsol.exe either does not exist or it is not executable. To skip this validation, call set_executable with validate=False."
The program works well when exe is directly used and the same program gives the above error when exe file is triggered through VBA Macro. Please help solving this problem.
Edit:
Part of VBA code that calls the exe
With CreateObject("WScript.Shell")
.Run """" + NewFilePath + """", 1, True
End With
NewFilePath is the location of the exe file.
Please note, GLPK solver works when the exe is executed directly. When called from VBA macro, other sections of python program also works except for the GLPK. The only thing that does not work is GLPK when the exe is called from Macro.
Error Message -
WARNING: Failed to create solver with name '_glpk_shell': Failed to set
executable for solver glpk. File with name=glpk-4.65\w64\glpsol.exe either
does not exist or it is not executable. To skip this validation, call
set_executable with validate=False.
Traceback (most recent call last):
File "pyomo\opt\base\solvers.py", line 152, in __call__
File "pyomo\solvers\plugins\solvers\GLPK.py", line 119, in __init__
File "pyomo\opt\solver\shellcmd.py", line 55, in __init__
File "pyomo\opt\solver\shellcmd.py", line 100, in set_executable
ValueError: Failed to set executable for solver glpk. File with name=glpk-4.65\w64\glpsol.exe either does not exist or it is not executable. To skip this validation, call set_executable with validate=False.
Traceback (most recent call last):
File "optimization.py", line 459, in <module>
File "pyomo\opt\base\solvers.py", line 105, in solve
File "pyomo\opt\base\solvers.py", line 122, in _solver_error
RuntimeError: Attempting to use an unavailable solver.
The SolverFactory was unable to create the solver "_glpk_shell"
and returned an UnknownSolver object. This error is raised at the point
where the UnknownSolver object was used as if it were valid (by calling
method "solve").
The original solver was created with the following parameters:
executable: glpk-4.65\w64\glpsol.exe
type: _glpk_shell
_args: ()
options: {}
[15784] Failed to execute script 'optimization' due to unhandled exception!
I figured out the problem. VBA triggers exe file from the cmd default folder. Python/Pyomo looks for the solver in the same folder. From VBA, by going to the folder in which exe and GLPK solver are from cmd and triggering the exe make the program work. Following is the change
With CreateObject("WScript.Shell")
Cmd1 = "cd " & DistFolder
Cmd2 = """" + NewFilePath + """"
Connector = " & "
Commands = "cmd.exe /K " & Cmd1 & Connector & Cmd2
.Run Commands, 1, True
End With
#Tim Williams might be right with his comment.
I'm trying to make an executable file for a project so my friends don't need to install python, using pyinstaller
When using pyinstaller with "-w"
The executable shows an Attribute error
Traceback (most recent call last):
File "main.py", line 7, in <module>
display = calendar_object.make_calendar()
AttributeError: 'Calendar' object has no attribute 'make_calendar'
but when I open main.py in the terminal it is completely fine.
When using pyinstaller without "-w"
It opens and closes immediately, and yes I have a while loop and an input inside so I'm guessing there's again, something wrong with my file
Temporary Solution:
Inserting all the separate files into one file.
Code Sample:
main.py
calendar.py
You seem to be using a name for your class that is mimicking the python internal calendar class.
Rename your class and you should be fine
I'm trying to write a chatting app that when run the first time deletes itself from the current position. Now the code is:
import os
import sys
file=sys.argv[0]
os.remove(file)
if i run it as .py file, it works just fine. Anyway if compile it with pyinstaller, when run by terminal it raises:
Traceback (most recent call last):
File "tests.py", line 6, in <module>
PermissionError: [WinError 5] Denied access: 'tests.exe'
[14320] Failed to execute script 'tests' due to unhandled exception!
nothing changes if i run it as administrator or assigning the file permissions with os.chmod. I have python 3.10, i tried both with python 3.9 and 3.10 and it does not work. I even tried running the command del with the subprocess module with the same result.
This works as .py file because the actual executable is the compiled version of the source code - a separate file/memory space. While the compilation is running the source code .py file is closed and can be removed.
When the program is compiled and run as a .exe file it will not remove itself because it is still open and running and therefore has a permission access denied error.
It is trying to remove itself because file = sys.argv[0]
(If you want to remove your running exe maybe start another program that does the removing from the exe and exit exe so that it is closed before removal - kind of awkward.)
I have this Python code: https://github.com/andreagrandi/aoc_2019/tree/master/aoc
which runs perfectly from the terminal (Python 3 required) if I do for example: python aoc_03.py
But if I try to run it from VSCode, taking advantage of the Python extension and integration, I get this error:
(aoc) ➜ advent_of_code_2019 git:(master) /Users/andrea/.virtualenvs/aoc/bin/python /Users/andrea/Documents/advent_of_code_2019/aoc/aoc_03.py
Traceback (most recent call last):
File "/Users/andrea/Documents/advent_of_code_2019/aoc/aoc_03.py", line 70, in <module>
with open('aoc_03_input.txt', 'r') as file:
FileNotFoundError: [Errno 2] No such file or directory: 'aoc_03_input.txt'
My guess is that when invoked from VSCode, the script is run from a different path, so it cannot find the file aoc_03_input.txt which is located in the same folder of the script.
How do I tell VSCode to run my script from the /Users/andrea/Documents/advent_of_code_2019/aoc/ folder, so that it will be able to find my input file?
Thanks
Actually, I should have tried more before asking this question, because I just found the solution, but at this point I will write it here in case it can be useful to anyone:
If I change the path in this way:
with open('./aoc_03_input.txt', 'r') as file:
The file is being open correctly when I run the code in VSCode and when I run it from the terminal. Tested under OSX (but it should work under Linux too. Not sure about Windows).
I have a newbie question about creating osquery extensions using osquery-python. I Created a small extension that gets some additional RPM info from my linux system. Following the instructions in the docs, I added the path to the extension in /etc/osquery/extensions.load to get it to autoload. I restarted osqueryd and I see the extension running using ps ax.
If I interactively run osqueryi, I can see the table and get data. It all works perfectly.
However, when I run an osqueryi command 'one-liner' such as :
osqueryi .tables
I get a bunch of the following errors with my output:
#INFO:thrift.transport.TSocket:Could not connect to /root/.osquery/shell.em
Traceback (most recent call last):
File "build/bdist.linux-x86_64/egg/thrift/transport/TSocket.py", line 104, in open
handle.connect(sockaddr)
File "/usr/lib64/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 2] No such file or directory
ERROR:thrift.transport.TSocket:Could not connect to any of ['/root/.osquery/shell.em']
What have I done wrong?
Extensions are run in a separate process. You can see the socket errors, which indicate the extension process cannot communicate with osquery process. Make sure osqueryd or osqueryi is running. Link: osquery doc page for extensions.