【问题标题】:Cython compiled app requires python to be installed?Cython 编译的应用程序需要安装 python?
【发布时间】:2014-09-01 03:46:19
【问题描述】:

我有以下小程序:

import urllib2,os
urls = ['http://stahlworks.com/dev/sfk/sfk.exe','http://stahlworks.com/dev/sfk/sfk.exe','http://stahlworks.com/dev/sfk/sfk.exe','http://stahlworks.com/dev/sfk/sfk.exe']
for fruit in urls:
url = fruit

file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
os.system('cls')
file_size_dl = 0
block_sz = 8192
while True:
    buffer = u.read(block_sz)
    if not buffer:
        break

    file_size_dl += len(buffer)
    f.write(buffer)
    status = r"%10d  [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
    status = status + chr(8)*(len(status)+1)
    print status,

f.close()

我使用 Cython 编译它:

python cython.py --embed -o hello.c h.py

然后我使用 gcc 编译它:

gcc.exe -I"c:\python27\include" -L"c:\python27\libs" hello.c -ohello.exe -lpython27

编译后它运行良好,直到我在没有将 python/python27 重命名为 python27x 的计算机上尝试它,然后我收到以下错误:

The application was unable to start correctly (0xc000007b). Click OK to close the application.

有什么办法可以解决这个问题并构建一个真正独立的应用程序?

【问题讨论】:

  • 是的,你需要......使用 Cython,你只能获得一个从 Python 中“可导入”的编译模块

标签: python c++ c gcc cython


【解决方案1】:

我已经使用 py2exe (http://www.py2exe.org/) 在 Windows 应用程序中取得了相当大的成功。它以一种很好的方式打包了运行所需的东西,包括基本的 python 库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 1970-01-01
    • 2016-09-23
    相关资源
    最近更新 更多