Create a .exe from python .py file
Mar 1, 2021
#pip install pythonnet pyinstaller
Note: in the code where ever you are using a file directly , use the below function to call that file.
import os
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
# resultObj = parseXML(resource_path(xmlName))
# instead of #resultObj = parseXML(xmlName)
then:
pyinstaller — onefile hello.py
Or to add files in the same .exe
pyinstaller — onefile — add-data “*.xml;.” hello.py