简体   繁体   中英

ImportError: No module named xxx

from lib import mod_a 
print mod_a.MyClassName 
Result:<class 'lib.mod_a.MyClassName'>

print __import__("mod_a").MyClassName
Result:<class 'mod_a.MyClassName'>

When run as exe (created by py2exe),raise an error

print mod_a.MyClassName
Result:<class 'lib.mod_a.MyClassName'>


#Error
print __import__("mod_a").MyClassName            

Traceback (most recent call last): File "test.py", line 28, in
print import ("mod_a").MyClassName
ImportError: No module named mod_a


This is my setup.py

from distutils.core import setup  
import py2exe
import sys

includes = ["encodings", "encodings.*"]
sys.argv.append("py2exe")
sys.argv.append("-p lxml,gzip")
options = {"py2exe": {
                  "compressed": 1,
                  "optimize": 2,
                  "ascii": 0,
                  "bundle_files": 1,
                  }
        }
setup(
        version = "",
        description = "",
        name = "",
        options = options,
        zipfile=None,
        console = [{"script":'test.py',
                    'icon_resources':[(1, 'update.ico')]}])
print sys.modules["lib.mod_a"].MyClassName

在exe上运作良好!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM