Python 为什么在安装 cx_freeze 后出现“没有名为 cx_Freeze 的模块”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13906343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 09:54:50  来源:igfitidea点击:

Why am I getting a "no module named cx_Freeze" error after installing cx_freeze?

pythonwindowscx-freeze

提问by bla bla

I am trying to compile a python program and I am using python 3.2. So I downloaded cx_freezeand installed it. When I try to run the setup.pyin cmd it says:

我正在尝试编译一个 python 程序,我正在使用 python 3.2。所以我下载了cx_freeze并安装了它。当我尝试在 cmd 中运行setup.py 时,它说:

"importerror: no module named cx_freeze" 

I have removed cx_freezeand tried to re-install it, this time however, in the "select the location where cx_freeze should be installed"part of the installation I selected python from registry (which is all I did before) and also selected "python from another location"(and choose my C:\python32\ directory). Then I got this error:

我已经删除了cx_freeze并尝试重新安装它,但是这次,在安装的“选择应安装 cx_freeze 的位置”部分中,我从注册表中选择了 python(这是我之前所做的全部),并且还选择了“python从另一个位置”(并选择我的 C:\python32\ 目录)。然后我得到了这个错误:

"There is a problum with this windows installation package. a program required for this install to complete could not be run."

note: in my setup.pyfile is the following:

注意:在我的setup.py文件中如下:

from cx_freeze import *

Setup(
    name = "",
    version ="0.1",
    description ="",
    executables = [Executable("")] ,
)    

采纳答案by Slobodan Stevic

Finally found the solution to this problem! Been trying for two days and a programmer friend helped me (I'm not a programmer myself).

终于找到了解决这个问题的办法!尝试了两天,一个程序员朋友帮助了我(我自己不是程序员)。

So, when you type in "python setup.py build" to cmd, what it tries to do is look for python.exe in the folder you are in, and if it doesn't find it there then looks to system paths (which you can access with the command "echo %PATH%").

因此,当您在 cmd 中键入“python setup.py build”时,它试图做的是在您所在的文件夹中查找 python.exe,如果在那里找不到它,则查找系统路径(其中您可以使用命令“echo %PATH%”访问)。

So it looks there, it finds python and runs it - but python doesn't have cx_Freeze. Why? Because the python in the system path is an older version you have!! For me it was 2.6.5, despite me using 3.3. And this older version naturally didn't have cx_Freeze in it because I installed it to 3.3. This also explains why trying "import cx_Freeze" in IDLE works without problems.

所以它看起来在那里,它找到 python 并运行它 - 但 python 没有 cx_Freeze。为什么?因为系统路径中的python是你的旧版本!!对我来说它是 2.6.5,尽管我使用的是 3.3。而这个旧版本自然没有cx_Freeze,因为我把它安装到了3.3。这也解释了为什么在 IDLE 中尝试“import cx_Freeze”没有问题。

To see which version of python cmd is calling, type only "python" in cmd and it will show you.

要查看正在调用哪个版本的 python cmd,只需在 cmd 中键入“python”,它就会显示出来。

Ok, so the quick solution is to simply add the full absolute path leading to desired python.exe. For python 3.3 it's:

好的,所以快速解决方案是简单地添加通向所需 python.exe 的完整绝对路径。对于 python 3.3,它是:

c:\python33\python setup.py build

The long-term solution is to add python 3.3 to your system paths. I haven't done it myself, but this should be the info on how to do it http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx

长期解决方案是将 python 3.3 添加到您的系统路径。我自己没有做过,但这应该是关于如何做的信息http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in -windows-7.aspx

It's a late answer, but I hope this at least helps someone else. Enjoy your cx_Freeze

这是一个迟到的答案,但我希望这至少可以帮助其他人。享受你的 cx_Freeze