Skip to content

Instantly share code, notes, and snippets.

@melpon
Created Jun 9, 2012
Embed
What would you like to do?
$ pwd
/tmp/module
$ tree
.
├── fluent
│ ├── __init__.py
│ └── sender.py
└── plugin
├── __init__.py
└── fluent.py
$ cat plugin/fluent.py
import sys
sys.path.append('/tmp/module/fluent')
print sys.path
import fluent.sender
print 'fluent'
$ cat fluent/sender.py
print 'fluent.sender'
$ python -V
Python 2.7.2
$ python plugin/fluent.py
['/tmp/module',(中略), '/tmp/module/fluent']
Traceback (most recent call last):
File "plugin/fluent.py", line 6, in <module>
import fluent.sender
File "/tmp/module/plugin/fluent.py", line 6, in <module>
import fluent.sender
ImportError: No module named sender
@cocoatomo
Copy link

cocoatomo commented Jun 9, 2012

無理矢理

$ cat plugin/fluent.py
import sys

# sys.path.insert(0, '/private/tmp/module/fluent')
# print sys.path

import imp
imp.load_module('fluent.sender',
                open('/private/tmp/module/fluent/sender.py'),
                '/private/tmp/module/fluent/sender.py',
                ('', 'r', imp.PY_SOURCE))

# import fluent.sender

print 'fluent'

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