当前位置 : 主页 > 编程语言 > python >

问题解决系列:NameError: name 'platform_system' is not defined

来源:互联网 收集:自由互联 发布时间:2022-12-20
问题场景 使用​​pip​​​安装依赖的时候,更新之后,更新的依赖不能用。比如我将机器的​​ansible​​​版本指定安装​​2.7.11​​​版本,安装成功之后,使用命令​​ansible

问题场景

使用 ​​pip​​​安装依赖的时候,更新之后,更新的依赖不能用。比如我将机器的​​ansible​​​版本指定安装​​2.7.11​​​版本,安装成功之后,使用命令​​ansible --version​​的时候,提示报错,报错具体提示如下:

ERROR! Unexpected Exception, this is probably a bug: name 'platform_system' is not definedthe full traceback was:Traceback (most recent call last): File "/bin/ansible", line 97, in <module> mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass) File "/usr/lib/python2.7/site-packages/ansible/cli/__init__.py", line 38, in <module> from ansible.inventory.manager import InventoryManager File "/usr/lib/python2.7/site-packages/ansible/inventory/manager.py", line 38, in <module> from ansible.plugins.loader import inventory_loader File "/usr/lib/python2.7/site-packages/ansible/plugins/loader.py", line 22, in <module> from ansible.parsing.utils.yaml import from_yaml File "/usr/lib/python2.7/site-packages/ansible/parsing/utils/yaml.py", line 17, in <module> from ansible.parsing.yaml.loader import AnsibleLoader File "/usr/lib/python2.7/site-packages/ansible/parsing/yaml/loader.py", line 30, in <module> from ansible.parsing.yaml.constructor import AnsibleConstructor File "/usr/lib/python2.7/site-packages/ansible/parsing/yaml/constructor.py", line 29, in <module> from ansible.parsing.vault import VaultLib File "/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py", line 42, in <module> from cryptography.hazmat.backends import default_backend File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/__init__.py", line 7, in <module> import pkg_resources File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 3007, in <module> working_set.require(__requires__) File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 728, in require needed = self.resolve(parse_requirements(requirements)) File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 631, in resolve requirements.extend(dist.requires(req.extras)[::-1]) File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2489, in requires dm = self._dep_map File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2700, in _dep_map self.__dep_map = self._compute_dependencies() File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2733, in _compute_dependencies common = frozenset(reqs_for_extra(None)) File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2730, in reqs_for_extra if req.marker_fn(override={'extra':extra}): File "/usr/lib/python2.7/site-packages/_markerlib/markers.py", line 113, in marker_fn return eval(compiled_marker, environment) File "<environment marker>", line 1, in <module>NameError: name 'platform_system' is not defined

问题环境

软件

版本

python

2.7

pip

8.1.2

setuptools

0.9.8

问题原因

指定软件版本进行更新的时候,软件本身依赖的​​setuptools​​​版本不兼容当前机器的版本。所以更新​​setuptools​​​依赖即可。不过为了保险起见,最好连​​pip​​都一起更新。

解决方案

使用​​root​​用户执行以下命令

pip install --upgrade pippip install --upgrade setuptools

结果

使用命令​​ansible --version​​命令之后,可以正常显示,如下:

ansible 2.7.11 config file = /home/tidb/tidb-ansible/ansible.cfg configured module search path = [u'/home/tidb/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /bin/ansible python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

总结

版本依赖冲突是一个比较常见的问题,主要是分析背后的依赖问题,根据具体情况即可解决问题。

随缘求赞

如果我的文章对大家产生了帮忙,可以在文章底部点个赞或者收藏; 如果有好的讨论,可以留言; 如果想继续查看我以后的文章,可以左上角点击关注

也可以扫描以下二维码,关注我的公众号:枫夜之求索阁,查看我最新的分享!

问题解决系列:NameError: name

问题解决系列:NameError: name

上一篇:python 九九乘法表 for循环
下一篇:没有了
网友评论