-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Black MAPDL window opens when compiling a program with PyMAPDL #2988
Comments
Hi @PaulCreusy I haven't work much on packing PyMAPDL in an executable using pyinstaller. Can you share the code you use to create the compiled executable (aka the pyinstaller commands or files)?? |
Hi, thank you for your quick answer, here is a script that will allow you to compile the example included in the issue. The example should be placed in a file called main.py for this script to work. Also because some files must be included manually after the packaging, please make sure that the versions of the pyansys_tools_versioning and ansys_tools_path are the ones specified in my pip freeze or in the paths below. Otherwise, please change them to match yours. import os
from distutils.dir_util import copy_tree
from site import getsitepackages
# Find the location of Python's site packages directory
print(getsitepackages())
site_packages_path = getsitepackages()[-1]
PACKAGE_NAME = "MyPackage"
# Package with PyInstaller
os.system(f"pyinstaller --noconsole -n {PACKAGE_NAME} main.py")
# Include additional files to avoid crash on start
copy_tree(site_packages_path + "/ansys/api", f"dist/{PACKAGE_NAME}/_internal/ansys/api")
copy_tree(site_packages_path + "/pyansys_tools_versioning-0.5.0.dist-info",
f"dist/{PACKAGE_NAME}/_internal/pyansys_tools_versioning-0.5.0.dist-info")
copy_tree(site_packages_path + "/ansys_tools_path-0.4.1.dist-info",
f"dist/{PACKAGE_NAME}/_internal/ansys_tools_path-0.4.1.dist-info") |
Probably you can replace the versions in the hardcoded paths using: try:
import importlib.metadata as importlib_metadata
except ModuleNotFoundError: # pragma: no cover
import importlib_metadata
__version__ = importlib_metadata.version("ansys-mapdl-core") Or maybe just importing the library and read the version:
I am currently quite busy with other projects, I won't have time to check this until later next week. I hope this is OK. Please keep pinging here if I dont contact you back by then.
|
The problem is not urgent for me so later next week would be perfect. Thank you for your help and for the version tip. It will be very helpful for me! |
Hello @germa89, do you have news about this issue ? |
Hi @PaulCreusy I am re-reading your issue:
The default Windows OS behaviour is to open another window which can be a black MAPDL window, but it might be minimized by default. At least, that is what I see when I run it in my Windows 11 machine. There is always another window whenever MAPDL is running. If you click on that minimized window, the window will maximize it showing a black window which is probably what you are seeing also when you compile the image. Hence, I think when you compile the image, you cannot avoid seeing that black window, because you see it also when you are working normally (using python scripts). @clatapie can you confirm my statements? Is there always a black windows running on Windows OS?
Regarding this, this is a very interesting tip. If that works, I might implement it in PyMAPDL so MAPDL is always hidden to the user. Thank you ! |
Reference: https://stackoverflow.com/questions/2935704/running-shell-commands-without-a-shell-window
|
Thank you for your answer and continuing to work on this issue.
So just in case I would like to clarify the point. When using Python scripts I don't see the MAPDL console window. It is minimized automatically as expected and the one thing I can notice is an icon on my tasks bar. It is only for compiled images that the MAPDL window appears in foreground. |
Oh.. OK you want the MAPDL window to be minimized. I see. Well, I guess we could add subprocess.CREATE_NO_WINDOW to the subprocess call. But I will need to check side effects for this. Since I'm quite busy with other projects, I'm keeping this issue open to address this. However, feel free to propose that change in a PR. |
🤓 Before submitting the issue
pip install --upgrade --upgrade-strategy eager ansys-mapdl-core
in your activated virtual environment.🔍 Description of the bug
When using pymapdl and starting a MAPDL instance using the function
launch_mapdl
, MAPDL runs in the background and does not display any window which is the expected behavior. However, when packaging a script that uses this function, a black MAPDL empty console will appear and remain on screen as long as the instance is running.This is a problem for any program with a GUI using pymapdl that needs to be compiled. I am not able to test on Linux to see if the problem also exists but it could be simply solved on Windows by adding the following argument
creationflags=0x08000000
in the subprocess command that calls the MAPDL executable file.🕵️ Steps To Reproduce
💻 Which Operating System are you using?
Windows
🐍 Which Python version are you using?
3.11
💾 Which MAPDL version are you using?
23.1
📝 PyMAPDL Report
Show the Report!
📝 Installed packages
Show the installed packages!
📝 Logger output file
Show the logger output file.
The text was updated successfully, but these errors were encountered: