简体   繁体   English

导入错误:没有名为 py2exe 的模块

[英]ImportError: no module named py2exe

I get this error when I try to use one of the py2exe samples with py2exe.当我尝试将 py2exe 示例之一与 py2exe 一起使用时,出现此错误。

File "setup.py", line 22, in ?
   import py2exe
ImportError: no module named py2exe

I've installed py2exe with the installer, and I use python 2.6.我已经用安装程序安装了 py2exe,我使用的是 python 2.6。 I have downloaded the correct installer from the site (The python 2.6 one.)我已经从该站点下载了正确的安装程序(python 2.6 之一。)

My path is set to C:\\Python26 and I can run normal python scripts from within the command prompt.我的路径设置为 C:\\Python26,我可以从命令提示符中运行普通的 python 脚本。

Any idea what to do?知道该怎么做吗?

Thanks.谢谢。

Edit: I had python 3.1 installed first but removed it afterwards.编辑:我先安装了 python 3.1,但后来将其删除。 Could that be the problem?这可能是问题吗?

Sounds like something has installed Python 2.4.3 behind your back, and set that to be the default.听起来好像有什么东西在你背后安装了 Python 2.4.3,并将其设置为默认值。

Short term, try running your script explicitly with Python 2.6 like this:短期内,尝试使用 Python 2.6 显式运行您的脚本,如下所示:

c:\Python26\python.exe setup.py ...

Long term, you need to check your system PATH (which it sounds like you've already done) and your file associations, like this:从长远来看,您需要检查您的系统路径(听起来您已经完成了)和您的文件关联,如下所示:

C:\Users\rjh>assoc .py
.py=Python.File

C:\Users\rjh>ftype Python.File
Python.File="C:\Python26\python.exe" "%1" %*

Simply removing Python 2.4.3 might be a mistake, as presumably something on your system is relying on it.简单地删除 Python 2.4.3 可能是一个错误,因为您系统上的某些东西可能依赖于它。 Changing the PATH and file associations to point to Python 2.6 probably won't break whatever thing that is, but I couldn't guarantee it.更改 PATH 和文件关联以指向 Python 2.6可能不会破坏任何东西,但我不能保证。

Seems like you need to download proper py2exe distribution.似乎您需要下载正确的py2exe发行版。

Check out if your c:\\Python26\\Lib\\site-packages\\ contains py2exe folder.检查您的c:\\Python26\\Lib\\site-packages\\包含py2exe文件夹。

If you have any other versions of Python installed, it may be that another Python version is the default Python.如果您安装了任何其他版本的 Python,则可能是另一个 Python 版本是默认 Python。 Could this be the case?可能是这种情况吗? I believe the default Python installation is determined from a registry setting.我相信默认的 Python 安装是由注册表设置确定的。

I had the exact same issue and I just managed to get it solved - so I thought I would share my solution.我遇到了完全相同的问题,我只是设法解决了它 - 所以我想我会分享我的解决方案。

It turned out that my installation of CollabNet SVN contained an old version of Python that interfered with my recent Python2.7 installation.结果证明我安装的 CollabNet SVN 包含一个旧版本的 Python,它干扰了我最近安装的 Python2.7。

Replacing CollabNet SVN with VisualSVN (including a couple of reboots) did the trick.用 VisualSVN 替换 CollabNet SVN(包括几次重启)就成功了。 I know this is not a "pretty" solution, as it caused me to uninstall CollabNet SVN - a prettier solution might have been doing modifications to the PATH env.我知道这不是一个“漂亮”的解决方案,因为它导致我卸载了 CollabNet SVN - 一个更漂亮的解决方案可能已经对 PATH 环境进行了修改。 variable... However, I am now able to use py2exe :)变量...但是,我现在可以使用 py2exe :)

You might need to install the py2exe module globally, perhaps you might have installed to a virtualenv.您可能需要全局安装 py2exe 模块,也许您可​​能已安装到 virtualenv。 I had the same problem, installing the module globally fixed the problem我遇到了同样的问题,全局安装模块解决了问题

For the record, my very similar problem was caused by using a Cygwin prompt.作为记录,我非常相似的问题是由使用Cygwin提示引起的。 Using as standard cmd.exe shell instead worked (given all paths and correctly installed versions of python).使用标准cmd.exe shell 代替工作(给定所有路径和正确安装的 python 版本)。

This was because (stupid me) the Cygwin install had pulled down it's own version of /usr/bin/python .这是因为(愚蠢的我)Cygwin 安装已经删除了它自己的/usr/bin/python I equally fixed it by adding the Windows installed python location to the head of the Cygwin PATH=/cygdrive/c/Python27:$PATH .我同样通过将 Windows 安装的 python 位置添加到 Cygwin PATH=/cygdrive/c/Python27:$PATH的头部来修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM