PyInstaller:“ImportError:没有名为htmlentitydefs的模块”

时间:2014-01-03 12:04:35

标签: python python-2.7 packages pyinstaller cx-freeze

我用这样的pyinstaller创建了可执行文件(没有--onefile或其他选项)

> pyinstaller brdg2.py

当我运行它时,here's what i get (关闭之前命令提示符的屏幕截图)。

从其他线程开始,警告似乎是可以忽略的,所以问题就是

ImportError: No module named htmlentitydefs

修改:我使用cx_freeze创建的.exe获取the same ImportError ,因此它似乎与打包程序无关。

另外要添加一些信息,我刚刚重新安装了Python和必要的模块,我之前做过相同的操作时没有得到这个错误(虽然我确实得到了其他错误)。

1 个答案:

答案 0 :(得分:1)

在Python 3中htmlentitydefs模块已重命名为html.entities。2to3工具在将源转换为Python 3时将自动适应导入。

使用public class Member { public string Name { get; set; } public string Race { get; set; } public int CarryingWeight { get; set; } public int MaxCarryWeight { get; set; } public int MaxMana { get; set; } public int MeleeAttack { get; set; } public int RangeAttack { get; set; } public int Defense { get; set; } public int MaxHealth { get; set; } IBag bag = new LargeBag(); } public class LargeBag : IBag { public int Weight { get; set; } = 7; IItem[] items = new IItem[12]; } // I put all kinds of dynamic objects to a Dictionary and Serialized the whole // Dictionary with JSON, then saved it to a file. Dictionary<string, dynamic> savedObjects = new Dictionary<string, dynamic>(); savedObjects.Add("hero1", Globals.member1); savedObjects.Add("hero2", Globals.member2); var settings = new JsonSerializerSettings() { ContractResolver = new MyContractResolver() }; var saveData = JsonConvert.SerializeObject(savedObjects, settings); // When DeSerializing the Dictionary, i'm able to create the Heroes back with // .ToObject method, but the Bag's stuff aren't there Dictionary<string, dynamic> loadedObjects = new Dictionary<string, dynamic>(); loadedObjects = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(loadData); Member loadedMember1 = loadedObjects["member1"].ToObject<Member>(); Member loadedMember2 = loadedObjects["member2"].ToObject<Member>(); // JSON settings used public class MyContractResolver : Newtonsoft.Json.Serialization.DefaultContractResolver { protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) { var props = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Select(p => base.CreateProperty(p, memberSerialization)) .Union(type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Select(f => base.CreateProperty(f, memberSerialization))) .Where(p => !p.PropertyName.Contains("k__BackingField")) .ToList(); props.ForEach(p => { p.Writable = true; p.Readable = true; }); return props; } } 代替html.entities

https://docs.python.org/3/library/html.entities.html