【问题标题】:Why does py2exe stop at "running"?为什么py2exe停止在“运行”?
【发布时间】:2016-05-25 14:33:24
【问题描述】:

我想在 Windows 7 和 Anaconda 下使用 py2exe 从 .py 脚本创建一个 .exe 文件。

所以我创建了一个 setup.py 文件:

from distutils.core import setup 
import py2exe 

setup(console=['mouseMove.py'], options = {'py2exe': {'packages': ['pyautogui']}})

现在我在 Windows-CMD 中导航到“mouseMove.py”和“setup.py”存在的目录并启动:

python setup.py py2exe

在 cmd 窗口中写着“正在运行 py2exe”,它保持在这种状态,没有其他任何事情发生。

有谁知道问题出在哪里?

mouseMove.py 的内容:

import pyautogui 
import sys 
xCoords = sys.argv[1] 
yCoords = sys.argv[2] 
pyautogui.moveTo(xCoords, yCoords) 
pyautogui.click()

【问题讨论】:

  • 你能给我们看看 mouseMove.py 吗?
  • 当然。但我也尝试了一个简单的“hello world”示例并且有相同的行为: import pyautogui import sys xCoords = sys.argv[1] yCoords = sys.argv[2] pyautogui.moveTo(xCoords, yCoords) pyautogui .click()
  • 这实际上对我有用。你能从 python 提示符成功import py2exeimport pyautogui 吗?
  • 当然,你不能真正让它工作,因为 xCoords 和 yCoords 是字符串类型,而 moveTo 需要整数。
  • 好吧,这是一个错误,但这不是问题,就像我说的,我还用一个简单的“hello-world”示例进行了尝试。我也可以导入包。该程序作为 .py 文件运行。也许问题与 anaconda 有关?

标签: python windows anaconda py2exe


【解决方案1】:

试试下面的 setup.py 文件。我希望它的工作。

 from distutils.core import setup
import py2exe
from distutils.filelist import findall
import os
import matplotlib
from glob import glob
matplotlibdatadir = matplotlib.get_data_path()
matplotlibdata = findall(matplotlibdatadir)
matplotlibdata_files = []
for f in matplotlibdata:
    dirname = os.path.join('matplotlibdata', f[len(matplotlibdatadir)+1:])
    matplotlibdata_files.append((os.path.split(dirname)[0], [f]))


setup(
    console=['resolution_finder.py'],
    options={
             'py2exe': {
                        'includes': ["sip", "PyQt4.QtGui","scipy.special._ufuncs_cxx"],
                        'packages' : ['matplotlib', 'pytz'],
                        'excludes': ['_gtkagg', '_tkagg'],
                        "dll_excludes": ["MSVCP90.dll"]   
                       }
            },


    data_files=matplotlib.get_py2exe_datafiles()
    #data_files=[('matplotlib.get_py2exe_datafiles()', [("Microsoft.VC120.CRT", glob(r'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\x86\Microsoft.VC120.CRT\*.*'))])]

    #data_files = [("Microsoft.VC120.CRT", glob(r'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\x86\Microsoft.VC120.CRT\*.*'))]

)

【讨论】:

  • 它对我不起作用,仍然存在相同的行为。
猜你喜欢
  • 2021-08-19
  • 2015-07-30
  • 1970-01-01
  • 2020-03-08
  • 1970-01-01
  • 1970-01-01
  • 2022-01-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多