Skip to content

Instantly share code, notes, and snippets.

@kjunichi
Last active January 25, 2016 06:32
Show Gist options
  • Save kjunichi/28398f0e86f9df80bdac to your computer and use it in GitHub Desktop.
Save kjunichi/28398f0e86f9df80bdac to your computer and use it in GitHub Desktop.
2016/1/8

Pythonでワンバイナリ

Zip圧縮したPythonスクリプトを実行

  • __main__.py
from testmod import foo

print 'Hello world'
foo.Message.printMsg()
  • testmod/foo.py
class Message():
        @classmethod
        def printMsg(self):
                print "Hello, world!"
  • testmod/__init__.py
  • 空のファイル
zip hoge __main__.py testmod/*
echo '#!/usr/bin/env python'>hoge
cat hoge.zip >>hoge
chmod +x hoge

学んだこと

ディレクトリ作って.pyスクリプト入れるだけPYTHONPATHいくら指定しても。

import modpath.mod

形式では呼べない。

modpath含むようにPYTHONPATH指定すれば、

import mod

では呼べる

関連

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment