当我尝试在CentOS 6上进行pip安装时,为什么会出现语法错误?

a11xaf1n  于 2022-11-07  发布在  其他
关注(0)|答案(2)|浏览(149)

我尝试在CentOS 6系统上安装名为cymysql的python模块,使用的命令如下
yum安装-y python-setuptools &&轻松安装pip && pip安装cymysql
但是,我收到一条错误消息,说有几行得到了语法错误:无效语法(请参阅下面的错误代码)---当我运行第三个命令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,但我不知道www.example.com文件在哪里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**
   )

www.example.com中的第57至62行Main.py

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)
u5i3ibmn

u5i3ibmn1#

我的天&tldr;啊
在基于RPM的发行版上,您尽可能多地使用RPM包。

从不以root用户身份运行pip

must not use pip as root user(或者自找麻烦)。有一个完整的Python包基础结构可以通过yum安装,这就是你应该使用的。
你仍然可以使用pip来安装Python模块,但只有在极少数情况下,当Python模块不能以包的形式提供时。在这种情况下,你 * 必须 * 在一个虚拟Python环境中使用pip。你的情况就是这样。
请确保您拥有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
ckx4rj1h

ckx4rj1h2#

不要在Centos 6系统上使用pip版本20,否则带有预编译c库的wheel会崩溃。长话短说,先这样做:

pip install --upgrade pip==20.1.0

之后就可以安装cymysql了

相关问题