Create a .exe from python .py file

#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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Mohammad Farman Abbasi
Mohammad Farman Abbasi

Written by Mohammad Farman Abbasi

Learning each day without giving up.

No responses yet

Write a response