Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can’t run zip file: “can't find '__main__' module”

I packed my program in a zip file on my machine, it contains __main__.pyc and works well on my machine and other machine, but when I copied it to third machine, it doesn’t work. The only information it gave is

/usr/local/bin/python3: can't find '__main__' module in 'main.zip'

This not really helping for me. I guess it might be because this machine is a virtual machine that runs on the cloud?

python3 on my machine is:

Python 3.3.1 (default, Apr 24 2013, 20:58:52)
[GCC 4.6.3] on linux

on the 3rd machine is:

Python 3.3.1 (default, Jan  8 2014, 18:36:12)
[GCC 4.6.3] on linux

The linux version on my machine is

Linux Svr2 3.2.0-34-generic-pae #53-Ubuntu SMP Thu Nov 15 11:11:12 UTC 2012 i686 i686 i386 GNU/Linux

on the 3rd machine is:

Linux ubuntu 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

My machine OS is 32bit and the target machine is 64bit, is that what makes the difference?

like image 583
user2003548 Avatar asked Sep 03 '25 10:09

user2003548


1 Answers

it contains __main__.pyc

My machine OS is 32bit and the target machine is 64bit

Yes, that’s likely what is causing the problems. pyc files are compiled versions of the source (which is stored in .py files). These compiled files are very version specific, and it’s very likely that a pyc compiled as 32bit won’t work on a 64bit Python although the version is the same.

Instead of using the pyc files, you should just store the py files within the zip. That way, the executing Python interpreter can just interpret the code as it needs to.

like image 139
poke Avatar answered Sep 04 '25 23:09

poke