1

I found that on my ubuntu15.10, I can not execute a *.pyc file like

$ echo 'print "Hello"' > print.py
$ chmod +x print.py
$ python -c 'import print'
$ ./print.pyc

But on another PC (ubuntu15.10 too), it can be executed. In this link( https://superuser.com/questions/73615/how-do-pyc-files-execute/73649#73649), I know that it was because my system has not a binfmt_misc entry for .pyc files. So my question is how to add it.

1 Answer 1

0

I am not sure what distro of Linux you have. For all except Debian based distros, this should work to install the necessary files:

import imp,sys,string
magic = string.join(["\\x%.2x" % ord(c) for c in imp.get_magic()],"") 
reg = ':pyc:M::%s::%s:' % (magic, sys.executable) 
open("/proc/sys/fs/binfmt_misc/register","wb").write(reg)

For Debian, you can install the necessary packages by installing binfmt-support.

Source

Best of luck, and happy coding!

Sign up to request clarification or add additional context in comments.

1 Comment

@ZHAOPengyu No problem! If the solution is correct, please remember to mark it as such for future programmers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.