Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run python module without the pyc extension

Tags:

python

I have a compiled Python 2.6 program on Linux called abc.pyc. If I run

./abc.pyc

it runs fine. However if I rename it to abc (i.e, without the pyc extension) it fails to run. It gives the error message:

ImportError: No module named abc

How can I run my program without the .pyc extension?

UPDATED: I want to run the compiled (pyc) version not the py version

Alternatively, I know I can compile modules to .so files using Cython, but can I compile my main Python program to something I can execute on a Linux platform? If so, a Cython command line example would be appreciated.

UPDATED I've raised the Cython question as a separate question.

like image 484
mozza Avatar asked Feb 25 '23 00:02

mozza


1 Answers

Create a file named 'abc' which contains:

#!/bin/sh
/usr/bin/env python -m abc

or is that giving away too much valuable source code if they can read that?

Note also that .pyc files aren't portable between different versions of Python. Redistributing the source really would be best for that reason quite apart from causing less annoyance to your users and less cost to yourself (in support time if nothing else).

like image 107
Duncan Avatar answered Feb 27 '23 13:02

Duncan