无法从集合中导入Set

无法从集合中导入Set

本文介绍了Python - 无法从集合中导入Set(“无模块命名集合”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习python而我正在尝试编写一些简单的东西。我正在使用OS X 10.8在Pydev(Eclipse)下开发。我使用64位.dmg安装程序安装了python 3.2。

I'm trying to learn python and I was trying to write something simple. I am developing under Pydev (Eclipse) using OS X 10.8. I installed python 3.2 using the 64bits .dmg installer.

我成功配置了Python解释器(或者我认为是这样,因为我实际上可以创建一个hello world项目和运行)。但由于某种原因,当我尝试导入Set( from sets import Set )时,我收到此错误:

I configured the Python interpreter successfully (or I think so, as I actually can create a "hello world" project and run it). But for some reason, when I try to import Set (from sets import Set) I get this error:

    from sets import Set;
ImportError: No module named sets

我也在命令行测试了它,并给出了我同样的错误。

I have tested it on command line too, and gives me the same error.

然后我查看了我的python3目录中的lib文件夹(在 /Library/Frameworks/Python.framework/Versions下) /3.2/lib/python3.2 / )并且它缺少sets.py文件!最初的2.7版本确实有 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 /

Then I have looked at the lib folder from my python3 directory (under /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/) and it's missing sets.py file!!! The original 2.7 version does have it at /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/

我也尝试将2.7 sets.py复制到3.2,但它既不起作用......
请知道我该怎么办?

I have also tried to copy the 2.7 sets.py to the 3.2, but it neither works...Please, do you know what have I to do?

推荐答案

您不再需要 sets 模块。 是Python 3中的内置类,无需导入即可使用。

You don't need the sets module anymore. set is a built-in class in Python 3 and can be used without import.

mySet = set()

这篇关于Python - 无法从集合中导入Set(“无模块命名集合”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:36