How to fix "ImportError: cannot import name 'setup' form 'cx_Freeze' "
How to fix "ImportError: cannot import name 'setup' form 'cx_Freeze' "
不好意思英语不好
我用 Python 3.7 和 pygame 做了一个游戏。
我试图用 cx_Freeze 版本 5.1.1 构建一个 exe,但是 ImportError
发生了...
有人上传了同样错误但未解决的问题:cx_Freeze- ImportError: cannot import name setup。
我尝试将 from cx_Freeze import setup, Executable
更改为 import cx_Freeze
,然后使用 cx_Freeze.setup
和 cx_Freeze.Executable
,但随后出现错误 setup not in cx_Freeze
...
这是我的install.py
代码
from cx_Freeze import setup, Executable
import cx_Freeze
setup(
name = "hello",
options={"build_exe": {"packages":["pygame"],
"included_files":["UFO.bmp","UFO_Monster.bmp","boss_Atack.jpg","boss.png","background_1.png","bullet.png","boom.png","shot.wav","explosion.wav","mybgm.wav","D2coding.ttf","Meteor.png"]}},
version = "0.1",
executables = [
cx_Freeze.Executable('Main.py'),
cx_Freeze.Executable('Boss_class.py'),
cx_Freeze.Executable('Boss_class_Attack.py'),
cx_Freeze.Executable('Meteor.py'),
cx_Freeze.Executable('UFO_class.py'),
cx_Freeze.Executable('UFO_Monster.py')
]
)
这是错误信息:
Traceback (most recent call last):
File "cx_Freeze.py", line 2, in
from cx_Freeze import setup, Executable
File "C:\Users```\source\repos\PythonGame\cx_Freeze.py", line 2, in
from cx_Freeze import setup, Executable
ImportError: cannot import name 'setup' from 'cx_Freeze' (C:\Users```\source\repos\PythonGame\cx_Freeze.py)
您的源目录中是否有一个名为 cx_Freeze.py
的文件,而不是通过包目录导入,也可能通过 pip 安装的目录导入?
路径显示 cx_Freeze.py
而不是已安装包的预期路径。
不好意思英语不好
我用 Python 3.7 和 pygame 做了一个游戏。
我试图用 cx_Freeze 版本 5.1.1 构建一个 exe,但是 ImportError
发生了...
有人上传了同样错误但未解决的问题:cx_Freeze- ImportError: cannot import name setup。
我尝试将 from cx_Freeze import setup, Executable
更改为 import cx_Freeze
,然后使用 cx_Freeze.setup
和 cx_Freeze.Executable
,但随后出现错误 setup not in cx_Freeze
...
这是我的install.py
代码
from cx_Freeze import setup, Executable
import cx_Freeze
setup(
name = "hello",
options={"build_exe": {"packages":["pygame"],
"included_files":["UFO.bmp","UFO_Monster.bmp","boss_Atack.jpg","boss.png","background_1.png","bullet.png","boom.png","shot.wav","explosion.wav","mybgm.wav","D2coding.ttf","Meteor.png"]}},
version = "0.1",
executables = [
cx_Freeze.Executable('Main.py'),
cx_Freeze.Executable('Boss_class.py'),
cx_Freeze.Executable('Boss_class_Attack.py'),
cx_Freeze.Executable('Meteor.py'),
cx_Freeze.Executable('UFO_class.py'),
cx_Freeze.Executable('UFO_Monster.py')
]
)
这是错误信息:
Traceback (most recent call last): File "cx_Freeze.py", line 2, in from cx_Freeze import setup, Executable File "C:\Users```\source\repos\PythonGame\cx_Freeze.py", line 2, in from cx_Freeze import setup, Executable ImportError: cannot import name 'setup' from 'cx_Freeze' (C:\Users```\source\repos\PythonGame\cx_Freeze.py)
您的源目录中是否有一个名为 cx_Freeze.py
的文件,而不是通过包目录导入,也可能通过 pip 安装的目录导入?
路径显示 cx_Freeze.py
而不是已安装包的预期路径。