gpt4 book ai didi

python - 导入错误 : cannot import name packages

转载 作者:太空宇宙 更新时间:2023-11-04 04:19:54 24 4
gpt4 key购买 nike

我使用的是 cx_Freeze 版本 5.1.1,我有一个 python 2.7.9 应用程序可以使用 cx_Freeze 进行打包。该应用程序正在使用 python 'requests' 模块(requests 的版本是 2.18.4)

这是我的 cx_Freeze setup.py 文件(注意我在要包含的包中特别包含“请求”):

from cx_Freeze import setup, Executable
import sys

from cx_Freeze import setup, Executable

packages_to_include =['lib','lib/DB','encodings.ascii','requests']

buildOptions = dict(
optimize=1,
excludes = ['tkinter'],
bin_includes = [
'libcrypto.so.1.0.0',
'libcrypto.so.10',
'libgssapi_krb5.so.2',
'libk5crypto.so.3',
'libkeyutils.so.1',
'libssl.so.1.0.1e',
'libssl.so.10'
],
includes = packages_to_include,
packages= ['urllib3','idna']
)

executables = [
Executable(
'workapp.py',
targetName = 'workapp'
)
]

setup(
name='Sample Flask App',
version = '0.1',
description = 'Sample Flask App',
#requires = ["requests"],
options = dict(build_exe = buildOptions),
executables = executables
)

构建已成功创建可执行文件,但在运行我的应用程序时出现以下错误:

Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/__startup__.py", line 14, in run
module.run()
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 26, in run
exec(code, m.__dict__)
File "vaas.py", line 2, in <module>
import requests
File "/usr/local/lib/python2.7/site-packages/requests/__init__.py", line 113, in <module>
from . import packages
ImportError: cannot import name packages

我认为这是我的 cx_Freeze 设置或请求的问题,但由于我告诉 cx_Freeze 包含“请求”,所以这应该有效。我检查了构建目录(cx_Freeze 构建请求模块定义了“包”,我可以找到它:

[user@centos-vm]$ ls build/exe.linux-x86_64-2.7/lib/requests/packages/
chardet idna urllib3

非常感谢任何帮助!

最佳答案

找到解决此问题的方法:

编辑:

/usr/local/lib/python2.7/site-packages/requests/__init__.py

并注释掉:

from . import packages

确实是很奇怪的问题。我解冻的应用程序工作正常,但在使用 cx_freeze 时需要上述解决方法。

关于python - 导入错误 : cannot import name packages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54683157/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com