开发者

How to create hook modules for PyInstaller?

开发者 https://www.devze.com 2023-03-14 05:43 出处:网络
I\'ve recently made a script using PyQt and a few other packages that I\'d like to distribute to other people, and I\'ve been trying to get it into an exe using PyInstaller.

I've recently made a script using PyQt and a few other packages that I'd like to distribute to other people, and I've been trying to get it into an exe using PyInstaller.

The problem I encounter though is the "Failed import, cannot find " which I gather is related to the fact that I need to create hook files for some modules. I've tried following the limited guide on the PyInstaller manual but that doesn't seem to work the way I've tried. Any ideas? The generated .exe file fails at the 'from import obspy.core import *' step, so presumably the imports that occur before it go through just fine.

My imports for the script are the following:

import os.path
import sys
import string
import fnmatch

import numpy as np

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from obspy.core import read
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as     NavigationToolbar
from matplotlib.widgets i开发者_Go百科mport MultiCursor
from obspy.signal import rotate
from obspy.signal import filter


The #1 rule is that a python script cannot have the same name as a module (i.e. mail.py would cause problems importing a module named 'mail'). My guess is maybe you have a script called obspy.py or a .pyc file with that name.

As far as my import setup for a custom module, this is what works for me.

Create a Module named Foo with a widget named Bar. In the file named Foo/__init__.py, list the modules to import:

import Bar

Then in your script:

From Foo import Bar

print Bar.helloworld

0

精彩评论

暂无评论...
验证码 换一张
取 消