1

Is it possible to create a Python Executable file (using PyInstaller or similar) that can in its code access other Python-files stored in a specific folder?

The reason for that it MUST be an Executable is that the script sometimes must be run from computers that has not it's own Python installed. I have no problem creating an executable (with PyInstaller for example) and they work fine. The python script itself loads various kinds of data into a database. But everytime there is a new kind of data that has to be loaded into the database I have to recreate the hole exe-file. I'm looking for a way for the executable to access python-files (with Data Load Instructions) so that the actual pyton load-files can be altered instead of the exe-file.

I have tried to find a solution using this:

import os, time
from subprocess import call

for file in os.listdir('.'):
    if file == 'loadInstructions.py':
        call(['python', file])
        print(file)

cwd = os.getcwd()
print(cwd)

input('To EXIT progran press ENTER.')
time.sleep(3)

It works running it from a python editor but when I turn this into an exe-file it does not. If I creat an exe-file with "call(['python', file])" commented out the rest works which I interpret that the exe-file can find the file in question but not run it.

I would be gratefule for any help.

mhelmers
  • 13
  • 2
  • Do you ever have to run the other file several times? If no, you could import it using `importlib`. If not: Try replacing `'python'` with `sys.executable` — Python is probably not on the path. – L3viathan Dec 06 '18 at 10:04

0 Answers0