当我输入:
username:~/Desktop/folder$ python
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, May 28 2015, 17:04:42)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import PySide
PySide已成功导入(因为我之前已经brew install pyside
)。换句话说,导入PySide时没有产生错误。但是,当我尝试运行PySide依赖的GUI(通过双击它)时,我得到:
ImportError: No module named 'PySide'
我有一种感觉,这与我的Python路径(最高层来自Anaconda)有关,而我的PySide安装在这里:/usr/local/Cellar
。
启动可执行文件时如何摆脱ImportError: No module named 'PySide'
?
修改
以下是用于编译GUI的cx_Freeze设置文件:
# A simple setup script to create an executable using PyQt4. This also
# demonstrates the method for creating a Windows executable that does not have
# an associated console.
#
# PyQt4app.py is a very simple type of PyQt4 application
#
# Run the build process by running the command 'python setup.py build'
#
# If everything works well you should find a subdirectory in the build
# subdirectory that contains the files needed to run the application
application_title = "MY_GUI" #what you want to application to be called
main_python_file = "GUI.py" #the name of the python file you use to run the program
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
includes = ["atexit","re"]
setup(
name = application_title,
version = "0.1",
description = "Sample cx_Freeze PyQt4 script",
options = {"build_exe" : {"includes" : includes }},
executables = [Executable(main_python_file, base = base)])