- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 python 脚本 (2.7),顶部有一些“有趣”的导入。我最初想使用 py2exe 将其编译成一个我可以更轻松地分发的 exe ( py2exe doesn't find all dependencies )。
我已经放弃了,正在尝试改用 cx-freeze。但是,我在那里也有问题。问题似乎是我添加到 Python 的库(jinja2 和 restkit)。我在我的 python 目录 ./Lib/site-packages/Jinja2-2.6-py2.7.egg/jinja2 和此处 ./Lib/site-packages/restkit-4.2.1-py2.7.egg/restkit 中看到它们。
这是我脚本中的导入:
import datetime
from jinja2 import Environment, PackageLoader
from optparse import OptionParser
from datetime import date, timedelta
from restkit import Resource, BasicAuth, request
我正在使用带有 cx-freeze 的 setup.py。这是 setup.py:
from cx_Freeze import setup, Executable
packages = ["restkit", "jinja2" , "restkit.client" ]
includes = []
includefiles = []
eggsacutibull = Executable(
script = "myScript.py",
initScript = None,
targetName = "myScript.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
name = "myScript",
version = "0.1",
author = 'vickery',
description = "MyScript description",
options = {"build_exe": {"includes":includes, "include_files": includefiles, "packages": packages}},
executables = [eggsacutibull]
)
我这样运行 cxfreeze:
cxfreeze myScript.py --target-dir exe
我在我的构建中得到了这个:
Missing modules:
? __pypy__ imported from jinja2.debug
? http_parser.http imported from restkit.client
? jinja2._debugsupport imported from jinja2.debug
? jinja2._markupsafe._speedups imported from jinja2._markupsafe
? jinja2.debugrenderer imported from jinja2.debug
? markupsafe imported from jinja2.utils
? pretty imported from jinja2.utils
? socketpool imported from restkit.conn
而且,当我尝试运行 exe 时,我得到了这个:
Traceback (most recent call last):
File "c:\Python27\lib\site-packages\restkit-4.2.1-py2.7.egg\restkit\__init__.py", line 9, in <module>
from restkit.conn import Connection
File "c:\Python27\lib\site-packages\restkit-4.2.1-py2.7.egg\restkit\conn.py", line 14, in <module>
from socketpool import Connector
ImportError: No module named socketpool
Traceback (most recent call last):
File "c:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec code in m.__dict__
File "myScript.py", line 12, in <module>
ImportError: cannot import name Resource
编辑:我现在像这样正确运行 cxfreeze:
python setup.py build
我还在我的 setup.py 中添加了 socketpool:
packages = [ "restkit", "jinja2" , "restkit.client", "restkit.conn", "socketpool" ]
但是,当我现在尝试构建时,出现构建错误:
$ python setup.py build
running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 32, in <module>
executables = [eggsacutibull]
File "c:\python27\lib\site-packages\cx_Freeze\dist.py", line 365, in setup
distutils.core.setup(**attrs)
File "c:\python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "c:\python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "c:\python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "c:\python27\lib\distutils\command\build.py", line 127, in run
self.run_command(cmd_name)
File "c:\python27\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "c:\python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "c:\python27\lib\site-packages\cx_Freeze\dist.py", line 235, in run
freezer.Freeze()
File "c:\python27\lib\site-packages\cx_Freeze\freezer.py", line 570, in Freeze
self.finder = self._GetModuleFinder()
File "c:\python27\lib\site-packages\cx_Freeze\freezer.py", line 325, in _GetModuleFinder
finder.IncludePackage(name)
File "c:\python27\lib\site-packages\cx_Freeze\finder.py", line 534, in IncludePackage
module = self._ImportModule(name, deferredImports)
File "c:\python27\lib\site-packages\cx_Freeze\finder.py", line 274, in _ImportModule
raise ImportError("No module named %r" % name)
ImportError: No module named 'socketpool'
让我感到困惑的是,我的脚本编译得很好。此外,我可以从 python shell 导入这些模块。例如:
$ python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import socketpool
>>> from restkit import Resource, BasicAuth, request
>>>
python 如何解析不同于 cxfreeze 的模块?
编辑2:从 python 我可以这样做:
>>> import socketpool
>>> print socketpool.__file__
c:\python27\lib\site-packages\socketpool-0.5.2-py2.7.egg\socketpool\__init__.pyc
那是一个非标准的寻找包裹的地方吗?我可以使用 PYTHONPATH 强制 cxfreez 在那里寻找 socketpool 吗?
谢谢
最佳答案
我知道这个帖子很旧,但我只花了 4 天时间弄明白了,它可能对其他人有帮助,所以这里是:
cx_freeze 中对 include_files 选项的描述具有误导性。如果你想为 build_exe 使用 include_files 选项,这里有一个你如何做的例子
include_files=[
(r"C:\Python27\Scripts\mk2ifcoremd.dll", "mk2ifcoremd.dll"),
(r"C:\Python27\Scripts\mk2ifportmd.dll", "mk2ifportmd.dll"),
(r"C:\Python27\Scripts\mk2imalloc.dll", "mk2imalloc.dll"),
(r"C:\Python27\Scripts\mk2iomp5md.dll", "mk2iomp5md.dll"),
(r"C:\Python27\Scripts\mk2mmd.dll", "mk2mmd.dll"),]
您必须有一个元组列表,其中包含源的绝对路径和目标的ONLY THE FILENAME。我在使用 cx_freeze 时遇到了麻烦,因为它确实/没有将所有必需的 DLL 复制到 dist 目录中。所以我的 exe 在我的机器上测试得很好,但在另一台没有安装 Python 的机器上无法运行。为了对此进行调试,我不得不反复将我的 Python 安装移开(将 C:\Python27 重命名为 C:_Python27)并查看是否缺少库。
这是一个适用于我的示例 setup.py 文件:
# invoke using:
# python setup.py build
from cx_Freeze import setup, Executable
import sys
import glob
import os
import zlib
import shutil
# Remove the existing folders folder
shutil.rmtree("build", ignore_errors=True)
shutil.rmtree("dist", ignore_errors=True)
########################################
# Here is a list of the Executable options
########################################
#"script": #the name of the file containing the script which is to be frozen
#"initScript": #the name of the initialization script that will be executed before the actual script is executed; this script is used to set up the environment for the executable; if a name is given without an absolute path the names of files in the initscripts subdirectory of the cx_Freeze package is searched
#"base": #the name of the base executable; if a name is given without an absolute path the names of files in the bases subdirectory of the cx_Freeze package is searched
#"path": #list of paths to search for modules
#"targetDir": #the directory in which to place the target executable and any dependent files
#"targetName": #the name of the target executable; the default value is the name of the script with the extension exchanged with the extension for the base executable
#"includes": #list of names of modules to include
#"excludes": #list of names of modules to exclude
#"packages": #list of names of packages to include, including all of the package's submodules
#"replacePaths": #Modify filenames attached to code objects, which appear in tracebacks. Pass a list of 2-tuples containing paths to search for and corresponding replacement values. A search for '*' will match the directory containing the entire package, leaving just the relative path to the module.
#"compress": #boolean value indicating if the module bytecode should be compressed or not
#"copyDependentFiles": #boolean value indicating if dependent files should be copied to the target directory or not
#"appendScriptToExe": #boolean value indicating if the script module should be appended to the executable itself
#"appendScriptToLibrary":#boolean value indicating if the script module should be appended to the shared library zipfile
#"icon": #name of icon which should be included in the executable itself on Windows or placed in the target directory for other platforms
#"namespacePackages": #list of packages to be treated as namespace packages (path is extended using pkgutil)
#"shortcutName": #the name to give a shortcut for the executable when included in an MSI package
#"shortcutDir": #the directory in which to place the shortcut when being installed by an MSI package; see the MSI Shortcut table documentation for more information on what values can be placed here.
MY_TARGET_EXE = Executable(
# what to build
script = "main.py",
initScript = None,
base = 'Win32GUI',
targetDir = r"dist",
targetName = "MyProgram.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
########################################
#Here is a list of the build_exe options
########################################
#1) append the script module to the executable
append_script_to_exe=False
#2) the name of the base executable to use which, if given as a relative path, will be joined with the bases subdirectory of the cx_Freeze installation; the default value is "Console"
base="Console"
#3) list of names of files to exclude when determining dependencies of binary files that would normally be included; note that version numbers that normally follow the shared object extension are stripped prior to performing the comparison
bin_excludes=[]
#4) list of names of files to include when determining dependencies of binary files that would normally be excluded; note that version numbers that normally follow the shared object extension are stripped prior to performing the comparison
bin_includes=[]
#5) list of paths from which to exclude files when determining dependencies of binary files
bin_path_excludes=[]
#6) list of paths from which to include files when determining dependencies of binary files
bin_path_includes=[]
#7) directory for built executables and dependent files, defaults to build/
build_exe="dist/"
#8) create a compressed zip file
compressed=False
#9) comma separated list of constant values to include in the constants module called BUILD_CONSTANTS in form <name>=<value>
constants=[]
#10) copy all dependent files
copy_dependent_files=True
#11) create a shared zip file called library.zip which will contain all modules shared by all executables which are built
create_shared_zip=True
#12) comma separated list of names of modules to exclude
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
'Tkconstants', 'Tkinter']
#13) include the icon in the frozen executables on the Windows platform and alongside the frozen executable on other platforms
icon=False
#13) comma separated list of names of modules to include
includes = ['sip', 'matplotlib.backends.backend_wxagg']
#15) list containing files to be copied to the target directory;
# it is expected that this list will contain strings or 2-tuples for the source and destination;
# the source can be a file or a directory (in which case the tree is copied except for .svn and CVS directories);
# the target must not be an absolute path
#
# NOTE: INCLUDE FILES MUST BE OF THIS FORM OTHERWISE freezer.py line 128 WILL TRY AND DELETE dist/. AND FAIL!!!
# Here is a list of ALL the DLLs that are included in Python27\Scripts
include_files=[
(r"C:\Python27\Scripts\mk2ifcoremd.dll", "mk2ifcoremd.dll"),
(r"C:\Python27\Scripts\mk2ifportmd.dll", "mk2ifportmd.dll"),
(r"C:\Python27\Scripts\mk2imalloc.dll", "mk2imalloc.dll"),
(r"C:\Python27\Scripts\mk2iomp5md.dll", "mk2iomp5md.dll"),
(r"C:\Python27\Scripts\mk2mmd.dll", "mk2mmd.dll"),
(r"C:\Python27\Scripts\mk2_avx.dll", "mk2_avx.dll"),
(r"C:\Python27\Scripts\mk2_blacs_ilp64.dll", "mk2_blacs_ilp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_intelmpi_ilp64.dll", "mk2_blacs_intelmpi_ilp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_intelmpi_lp64.dll", "mk2_blacs_intelmpi_lp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_lp64.dll", "mk2_blacs_lp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_mpich2_ilp64.dll", "mk2_blacs_mpich2_ilp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_mpich2_lp64.dll", "mk2_blacs_mpich2_lp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_msmpi_ilp64.dll", "mk2_blacs_msmpi_ilp64.dll"),
(r"C:\Python27\Scripts\mk2_blacs_msmpi_lp64.dll", "mk2_blacs_msmpi_lp64.dll"),
(r"C:\Python27\Scripts\mk2_cdft_core.dll", "mk2_cdft_core.dll"),
(r"C:\Python27\Scripts\mk2_core.dll", "mk2_core.dll"),
(r"C:\Python27\Scripts\mk2_def.dll", "mk2_def.dll"),
(r"C:\Python27\Scripts\mk2_intel_thread.dll", "mk2_intel_thread.dll"),
(r"C:\Python27\Scripts\mk2_mc.dll", "mk2_mc.dll"),
(r"C:\Python27\Scripts\mk2_mc3.dll", "mk2_mc3.dll"),
(r"C:\Python27\Scripts\mk2_p4n.dll", "mk2_p4n.dll"),
(r"C:\Python27\Scripts\mk2_pgi_thread.dll", "mk2_pgi_thread.dll"),
(r"C:\Python27\Scripts\mk2_rt.dll", "mk2_rt.dll"),
(r"C:\Python27\Scripts\mk2_scalapack_ilp64.dll", "mk2_scalapack_ilp64.dll"),
(r"C:\Python27\Scripts\mk2_scalapack_lp64.dll", "mk2_scalapack_lp64.dll"),
(r"C:\Python27\Scripts\mk2_sequential.dll", "mk2_sequential.dll"),
(r"C:\Python27\Scripts\mk2_vml_avx.dll", "mk2_vml_avx.dll"),
(r"C:\Python27\Scripts\mk2_vml_def.dll", "mk2_vml_def.dll"),
(r"C:\Python27\Scripts\mk2_vml_mc.dll", "mk2_vml_mc.dll"),
(r"C:\Python27\Scripts\mk2_vml_mc2.dll", "mk2_vml_mc2.dll"),
(r"C:\Python27\Scripts\mk2_vml_mc3.dll", "mk2_vml_mc3.dll"),
(r"C:\Python27\Scripts\mk2_vml_p4n.dll", "mk2_vml_p4n.dll"),
# These next DLLs appear to be copied correctly or as needed by cxfreeze...
# (r"C:\Python27\Scripts\libgcc_s_sjlj-1.dll", "libgcc_s_sjlj-1.dll"),
# (r"C:\Python27\Scripts\libgfortran-3.dll", "libgfortran-3.dll"),
# (r"C:\Python27\Scripts\libssp-0.dll", "libssp-0.dll"),
# (r"C:\Python27\Scripts\libstdc++-6.dll", "libstdc++-6.dll"),
# (r"C:\Python27\Scripts\pythoncom27.dll", "pythoncom27.dll"),
# (r"C:\Python27\Scripts\pywintypes27.dll", "pywintypes27.dll"),
]
#,("Microsoft.VC90.MFC", mfcfiles), ]
#16) include the script module in the shared zip file
include_in_shared_zip=True
#17) include the Microsoft Visual C runtime DLLs and (if necessary) the manifest file required to run the executable without needing the redistributable package installed
include_msvcr =False
#18) the name of the script to use during initialization which, if given as a relative path, will be joined with the initscripts subdirectory of the cx_Freeze installation; the default value is "Console"
init_script=""
#19) comma separated list of packages to be treated as namespace packages (path is extended using pkgutil)
namespace_packages=[]
#20) optimization level, one of 0 (disabled), 1 or 2
optimize=0
#21) comma separated list of packages to include, which includes all submodules in the package
packages = ['numpy.linalg']
#22) comma separated list of paths to search; the default value is sys.path
path = []
#23) Modify filenames attached to code objects, which appear in tracebacks. Pass a comma separated list of paths in the form <search>=<replace>. The value * in the search portion will match the directory containing the entire package, leaving just the relative path to the module.
replace_paths=[]
#24) suppress all output except warnings
silent=False
#25) list containing files to be included in the zip file directory; it is expected that this list will contain strings or 2-tuples for the source and destination
zip_includes=[]
setup(
version = "0.0",
description = "This is a program that works",
author = "Your Name Here",
name = "A text description",
options = {"build_exe": {
# "append_script_to_exe": append_script_to_exe,
# "base": base,
# "bin_excludes": bin_excludes,
# "bin_includes": bin_includes,
# "bin_path_excludes": bin_path_excludes,
# "bin_path_includes": bin_path_includes,
"build_exe": build_exe,
"compressed": compressed,
# "constants": constants,
"copy_dependent_files": copy_dependent_files,
# "create_shared_zip": create_shared_zip,
"excludes": excludes,
# "icon": icon,
"includes": includes,
"include_files": include_files,
# "include_in_shared_zip":include_in_shared_zip,
# "include_msvcr": include_msvcr,
# "init_script": init_script,
# "namespace_packages": namespace_packages,
# "optimize": optimize,
"packages": packages,
"path": path,
# "replace_paths": replace_paths,
# "silent": silent,
# "zip_includes": zip_includes,
}
},
executables = [MY_TARGET_EXE]
)
关于python - cx-freeze 找不到所有依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15486292/
我正在处理一组标记为 160 个组的 173k 点。我想通过合并最接近的(到 9 或 10 个组)来减少组/集群的数量。我搜索过 sklearn 或类似的库,但没有成功。 我猜它只是通过 knn 聚类
我有一个扁平数字列表,这些数字逻辑上以 3 为一组,其中每个三元组是 (number, __ignored, flag[0 or 1]),例如: [7,56,1, 8,0,0, 2,0,0, 6,1,
我正在使用 pipenv 来管理我的包。我想编写一个 python 脚本来调用另一个使用不同虚拟环境(VE)的 python 脚本。 如何运行使用 VE1 的 python 脚本 1 并调用另一个 p
假设我有一个文件 script.py 位于 path = "foo/bar/script.py"。我正在寻找一种在 Python 中通过函数 execute_script() 从我的主要 Python
这听起来像是谜语或笑话,但实际上我还没有找到这个问题的答案。 问题到底是什么? 我想运行 2 个脚本。在第一个脚本中,我调用另一个脚本,但我希望它们继续并行,而不是在两个单独的线程中。主要是我不希望第
我有一个带有 python 2.5.5 的软件。我想发送一个命令,该命令将在 python 2.7.5 中启动一个脚本,然后继续执行该脚本。 我试过用 #!python2.7.5 和http://re
我在 python 命令行(使用 python 2.7)中,并尝试运行 Python 脚本。我的操作系统是 Windows 7。我已将我的目录设置为包含我所有脚本的文件夹,使用: os.chdir("
剧透:部分解决(见最后)。 以下是使用 Python 嵌入的代码示例: #include int main(int argc, char** argv) { Py_SetPythonHome
假设我有以下列表,对应于及时的股票价格: prices = [1, 3, 7, 10, 9, 8, 5, 3, 6, 8, 12, 9, 6, 10, 13, 8, 4, 11] 我想确定以下总体上最
所以我试图在选择某个单选按钮时更改此框架的背景。 我的框架位于一个类中,并且单选按钮的功能位于该类之外。 (这样我就可以在所有其他框架上调用它们。) 问题是每当我选择单选按钮时都会出现以下错误: co
我正在尝试将字符串与 python 中的正则表达式进行比较,如下所示, #!/usr/bin/env python3 import re str1 = "Expecting property name
考虑以下原型(prototype) Boost.Python 模块,该模块从单独的 C++ 头文件中引入类“D”。 /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c)
如何编写一个程序来“识别函数调用的行号?” python 检查模块提供了定位行号的选项,但是, def di(): return inspect.currentframe().f_back.f_l
我已经使用 macports 安装了 Python 2.7,并且由于我的 $PATH 变量,这就是我输入 $ python 时得到的变量。然而,virtualenv 默认使用 Python 2.6,除
我只想问如何加快 python 上的 re.search 速度。 我有一个很长的字符串行,长度为 176861(即带有一些符号的字母数字字符),我使用此函数测试了该行以进行研究: def getExe
list1= [u'%app%%General%%Council%', u'%people%', u'%people%%Regional%%Council%%Mandate%', u'%ppp%%Ge
这个问题在这里已经有了答案: Is it Pythonic to use list comprehensions for just side effects? (7 个答案) 关闭 4 个月前。 告
我想用 Python 将两个列表组合成一个列表,方法如下: a = [1,1,1,2,2,2,3,3,3,3] b= ["Sun", "is", "bright", "June","and" ,"Ju
我正在运行带有最新 Boost 发行版 (1.55.0) 的 Mac OS X 10.8.4 (Darwin 12.4.0)。我正在按照说明 here构建包含在我的发行版中的教程 Boost-Pyth
学习 Python,我正在尝试制作一个没有任何第 3 方库的网络抓取工具,这样过程对我来说并没有简化,而且我知道我在做什么。我浏览了一些在线资源,但所有这些都让我对某些事情感到困惑。 html 看起来
我是一名优秀的程序员,十分优秀!