0

I'm calling subprocess.Popen on an exe file in this script, and it throws:

OSError: [Errno 8] Exec format error: '/Users/maxghenis/PolicyEngine/openfisca-us/openfisca_us/tools/dev/taxsim/taxsim35.exe'

The answer to subprocess.Popen(): OSError: [Errno 8] Exec format error in python? suggests adding #!/bin/sh to the top of the shell script. What's an analog to that for calling an exe instead of a shell script?

I'm on a Mac, and the file it's running is https://taxsim.nber.org/stata/taxsim35/taxsim35-unix.exe.

Max Ghenis
  • 14,783
  • 16
  • 84
  • 132
  • Which operating system are you running? Which operating system and architecture are the executable built for? – Charles Duffy Aug 12 '22 at 14:56
  • If you're on a UNIXy platform (or at least have UNIXy tools installed), you can use the `file` command to answer the second subset of questions there. – Charles Duffy Aug 12 '22 at 14:56
  • ...in general, though, this means that your operating system can't run the kind of executable you have in that location. (If it's a Windows executable and you're on Linux, it's possible that you might be able to get it to run using WINE configured through binfmt_misc; but that's not a sure thing unless the program in question has been tested to be compatible with WINE's reimplementation of the win32 API; if it's a 64-bit Windows executable and you're on 32-bit Windows, you're going to need to either recompile the executable or find compatible hardware). – Charles Duffy Aug 12 '22 at 15:00
  • Anyhow -- because this question can't be answered without details that aren't included (after having checked the repository and verified that the `.exe` file isn't committed to the source -- though even if it were, that wouldn't answer the subset of questions relating to your runtime environment), I'm voting-to-close as lacking a [mre]. Ping me when you update the question and I'll be glad to retract if it's in a fully answerable state. – Charles Duffy Aug 12 '22 at 15:05
  • @CharlesDuffy I edited the question to specify that I'm on a Mac and the file is https://taxsim.nber.org/stata/taxsim35/taxsim35-unix.exe. I can try to make a more minimal example but I'm not too familiar with subprocess (didn't write this code) so if you see anything based on just this I'd appreciate it. – Max Ghenis Aug 12 '22 at 15:20
  • `subprocess` can't make a program work on an operating system it isn't compiled for; let me download that file and see if I can make heads or tails of it. – Charles Duffy Aug 12 '22 at 15:27
  • (...or you could answer that yourself, by adding the output of `file taxsim35-unix.exe` to your question) – Charles Duffy Aug 12 '22 at 15:28
  • ...okay: `file taxsim35-unix.exe` emits `taxsim35-unix.exe: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=c5496d77cb56826e0754b07aba43bbf3753d34d0, with debug_info, not stripped`. So it's very misleadingly misnamed to imply that it's a generic "unix" executable; it's specifically a _Linux_ executable (for 64-bit Intel-compatible CPUs), and not expected to work on Mac. – Charles Duffy Aug 12 '22 at 15:29
  • If a Mac is all you have, I'd suggest looking at your options for virtual machines about now. – Charles Duffy Aug 12 '22 at 15:32
  • 1
    BTW, you might try running the program _without_ using Python at all. (If you can't run it from a shell command line, that gives you a pretty good hint you won't be able to run it any other way either). – Charles Duffy Aug 12 '22 at 16:26

2 Answers2

1

subprocess can only start programs that your operating system knows how to execute.

Your taxsim35-unix.exe is a Linux executable. MacOS cannot run them.

You'll need to either use a Linux machine to run this executable (real or virtual), or get a version compiled for Mac. https://back.nber.org/stata//taxsim35/taxsim35-osx.exe is likely to be the latter.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
0

I worked with the developers of taxsim for a while. I believe that the .exe files generated by taxsim were originally msdos only and then moved to Linux. They're not intended to be run by MacOS. I don't know if they ever released the FORTRAN code that generates them so that they can be run on MacOS. Your best bet for running taxsim (since there's no close open-source substitute) is to spin up an AWS or other Linux server.

  • There may be an older FreeBSD version if that's helpful (probably not). I remember helping making the code compile on FreeBSD. Contact the NBER and Dan Feenberg -- they're responsible to calls for help. – Michael Scott Asato Cuthbert Aug 13 '22 at 08:22