Rhel
Pip RHEL 中的無效語法錯誤
我正在嘗試
pip
在 RHEL 實例上安裝 python 包,但是當我嘗試執行任何 pip 命令時出現此錯誤。Pip 以前確實有效,但突然之間(不知道我做了什麼)它開始像這樣失敗。
[root@universe: ~]# pip --version Traceback (most recent call last): File "/usr/bin/pip", line 9, in <module> load_entry_point('pip==18.1', 'console_scripts', 'pip')() File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 378, in load_entry_point File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2566, in load_entry_point File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2260, in load File "/usr/lib/python2.6/site-packages/pip-18.1-py2.6.egg/pip/_internal/__init__.py", line 40, in <module> from pip._internal.cli.autocompletion import autocomplete File "/usr/lib/python2.6/site-packages/pip-18.1-py2.6.egg/pip/_internal/cli/autocompletion.py", line 8, in <module> from pip._internal.cli.main_parser import create_main_parser File "/usr/lib/python2.6/site-packages/pip-18.1-py2.6.egg/pip/_internal/cli/main_parser.py", line 8, in <module> from pip._internal.cli import cmdoptions File "/usr/lib/python2.6/site-packages/pip-18.1-py2.6.egg/pip/_internal/cli/cmdoptions.py", line 75 binary_only = FormatControl(set(), {':all:'}) ^ SyntaxError: invalid syntax [root@universe: ~]#
我試圖重新安裝 pip,但出現錯誤,提示
python-setuptools
缺少依賴項[root@universe: ~]# yum install python-pip Loaded plugins: product-id, rhnplugin, security, subscription-manager There was an error communicating with RHN. RHN Satellite or RHN Classic support will be disabled. Error Message: Please run rhn_register as root on this client Error Class Code: 9 Error Class Info: Invalid System Credentials. Explanation: An error has occurred while processing your request. If this problem persists please enter a bug report at bugzilla.redhat.com. If you choose to submit the bug report, please be sure to include details of what you were trying to do when this error occurred and details on how to reproduce this problem. Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package python-pip.noarch 0:7.1.0-1.el6 will be installed --> Processing Dependency: python-setuptools for package: python-pip-7.1.0-1.el6.noarch --> Finished Dependency Resolution Error: Package: python-pip-7.1.0-1.el6.noarch (epel) Requires: python-setuptools You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest [root@universe: ~]#
嘗試安裝
python-setuptools
顯示找不到包的消息[root@universe: ~]# yum install python-setuptools Loaded plugins: product-id, rhnplugin, security, subscription-manager There was an error communicating with RHN. RHN Satellite or RHN Classic support will be disabled. Error Message: Please run rhn_register as root on this client Error Class Code: 9 Error Class Info: Invalid System Credentials. Explanation: An error has occurred while processing your request. If this problem persists please enter a bug report at bugzilla.redhat.com. If you choose to submit the bug report, please be sure to include details of what you were trying to do when this error occurred and details on how to reproduce this problem. Setting up Install Process No package python-setuptools available. Error: Nothing to do [root@universe: ~]#
該錯誤似乎來自使用
set
文字語法{':all:'}
。在 Python 3.1中引入
set
了by using literal創建,並向後移植到 2.7 。{}
由於您使用的是 Python 2.6 解釋器,它沒有語法(並且不久前是 EOL 版),因此您得到了
SyntaxError
預期的結果。一種解決方案是全域升級 Python 版本,但您需要絕對確定,因為這很可能會破壞重要的系統組件。
另一個更好的選擇是使用 Python 解釋器的虛擬環境(例如
virtualenv
)。