我正在尝试通过以下命令在 CentOS 6 系统上安装一个名为 cymysql 的 python 模块
yum install -y python-setuptools && easy_install pip && pip install cymysql
但是我收到一条错误消息,说有几行得到 SyntaxError: invalid syntax (请参阅下面的错误代码)---它实际上是在我运行第三个命令时发生的 pip install cymysql
Traceback (most recent call last):
File "/usr/local/bin/pip", line 11, in <module>
load_entry_point('pip==21.0', 'console_scripts', 'pip')()
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 561, in load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2631, in load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2291, in load
File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 2297, in resolve
File "/usr/local/lib/python2.7/site-packages/pip-21.0-py2.7.egg/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
不太清楚这里发生了什么,只是想知道是否有人可以提供帮助? (我在这里附上了pip文件和main.py,但我不知道init.py文件在哪里)。顺便说一句,它是centOS 6,但我已经在服务器上安装了Python 3.6.10。当我运行命令 python3.6 -V ,我得到了python3.6.10
飞扬
PIP 文件代码:
#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==21.0','console_scripts','pip'
__requires__ = 'pip==21.0'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('pip==21.0', 'console_scripts', 'pip')() //**THIS IS LINE 11**
)
Main.py 中的第 57 到 62 行try:
cmd_name, cmd_args = parse_command(args)
except PipError as exc:
sys.stderr.write(f"ERROR: {exc}") //**THIS IS LINE 60**
sys.stderr.write(os.linesep)
sys.exit(1)
最佳答案
&tldr;
在基于 RPM 的发行版上,您尽可能多地使用 RPM 包。
从不跑pip
作为根用户
你 must not use pip
as root user (或自找麻烦)。
通过 yum
可以安装一整套 Python 包基础设施。这就是你应该使用的。
您仍然可以使用 pip
安装 Python 模块,但仅在 Python 模块不作为包可用的极少数情况下。在这种情况下,您必须使用 pip
在虚拟 Python 环境中。你的情况就是这样。
确保您有 fixed yum
for base, EPEL and set up SCLO repositories ,因为 CentOS 6 已停产。
然后:
# Ensure EPEL repository
yum -y install epel-release
# fix EPEL repo due to EOL:
curl https://www.getpagespeed.com/files/centos6-epel-eol.repo --output /etc/yum.repos.d/epel.repo
yum -y install centos-release-scl-rh
# don't forget to fix repository configuration due to EOL:
curl https://www.getpagespeed.com/files/centos6-scl-eol.repo --output /etc/yum.repos.d/CentOS-SCLo-scl.repo
curl https://www.getpagespeed.com/files/centos6-scl-rh-eol.repo --output /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
# install python 3.6 from Software collection packages (installing virtualenv will pick up both the base python and its pip package)
yum -y install rh-python36-python-virtualenv
现在您可以使用 pip 中的任何包创建一个虚拟环境,但您必须首先在您的 shell 中激活软件集合,例如:. /opt/rh/rh-python36/enable
cd ${HOME}
# create "myapp" virtual environment
virtualenv myapp
# install desired packages using virtualenv's pip (will install to the virtualenv and not damage your system)
./myapp/bin/pip install cymysql
关于python-2.7 - 当我尝试在 CentOS 6 上进行 pip 安装时,为什么会出现语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65897729/