[英]NameError: name 'json' is not defined
嘗試導入 Json,我的命令是pip install json
。 我正在使用 Windows 8.1
我在命令提示符中遇到的錯誤是
Could not find a version that satisfies the requirements json <from versions:>
No matching distribution found for json
。
我在 pycharm 上遇到的錯誤是
NameError: name 'json' is not defined
我嘗試導入numpy
並且效果很好。 我還檢查了Pip“找不到滿足要求的版本”和找不到滿足要求的版本 <package>
編輯:也參考此鏈接Python 3.5.1 : NameError: name 'json' is not defined並收到無法識別 sudo 的錯誤
如果它沒有在你的代碼中定義,你需要導入它。 這與 Python 中的任何名稱完全相同; 在你定義它之前你不能使用它。
import json
使用命令作為 simplejson 而不是像下面這樣的 json,
pip 安裝 simplejson
如果上面的命令也拋出錯誤使用下面的命令
easy_install simplejson
如果 pip 無法滿足請求,easy_install 有時會起作用。
我也遇到過類似的問題,pip 無法安裝 json 和 math 模塊(使用 python 3.x)。 最后,我發現有些模塊你根本不需要安裝——它們已經內置了。 :) 當然,您仍然需要在 .py 文件的頂部添加“import json”。 希望這可以幫助某人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.