skip to Main Content

I’m trying to install a python module called cymysql on a CentOS 6 system by commands like

yum install -y python-setuptools && easy_install pip && pip install cymysql

However I received an Error message saying there’re a few lines got SyntaxError: invalid syntax ( see the error code as following)—It actually happened when I run the third command 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

Not so sure what’s happening here, just wondering if anyone can help? (I enclosed the pip file and main.py here but I don’t know where is the init.py file).BTW, It’s centOS 6 but I have installed the Python 3.6.10 on the server.When I run the command python3.6 -V, I got

python3.6.10

FIY

PIP file Code:

 #!/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**
   )

Line 57 to 62 in 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)

2

Answers


  1. &tldr;

    On an RPM-based distro, you use RPM packages as much as possible.

    Never run pip as root user

    You must not use pip as root user (or asking for trouble).
    There is a whole infrastructure of Python packages installable through yum and this is what you should use.

    You can still use pip to install Python modules, but only in very rare cases when a Python module is not available as a package. In that case you must use pip inside a virtual Python environment. Your case is such.

    Make sure you have fixed yum for base, EPEL and set up SCLO repositories, since CentOS 6 is EOL.

    Then:

    # 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
    

    Now you can create a virtual environment with any packages from pip, but you have to activate the software collection in your shell first, example:

    . /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
    
    Login or Signup to reply.
  2. Do not go over pip version 20 on a Centos 6 system, otherwise wheels with precompiled c libraries will break.
    Long story short, do this first:

    pip install --upgrade pip==20.1.0
    

    After that you can install cymysql

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search