Skip to content
Advertisement

When I try to install the paramiko module in Python 3.5.1, I get an invalid syntax and cannot install it

When I tried to add a module called paramiko to Python 3.5.1 to add ssh communication functionality at the command prompt, I got the following error message and could not install it.

Traceback (most recent call last):
  File "C:UserstishiAppDataLocalProgramsPythonPython35librunpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "C:UserstishiAppDataLocalProgramsPythonPython35librunpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:UserstishiAppDataLocalProgramsPythonPython35libsite_packagespip__main__.py", line 21, in <module
    from pip._internal.cli.main import main as _main
  File "C:UserstishiAppDataLocalProgramsPythonPython35libsite_packagespipinternalclimain.py", line 60
    sys.stderr.write(f "ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

For the installation method, I entered the following

py -m pip install paramiko

I hope you can help me with this problem, thank you.

Advertisement

Answer

As shown in the error message, the string and variable editing specification f “ERROR: {exc}” is a formatted string literal, a specification that has been supported since Python 3.6.

Your 3.5.1 version does not support them, so you are probably getting SyntaxError: invalid syntax.

How to use f-strings (formatted string literals) in Python

Python 3.6 introduced the f-string (f-strings, format string, formatted string literal) mechanism, which makes it easier to write the redundant string method format().

Note that this is not available in versions prior to 3.5.

Formatting strings using formatted string literals (f-strings)

When formatting strings, formatted string literals (f-strings) are available since Python 3.6 as a more concise way to use the format method.

If you look closely, it looks like it’s not paramiko that’s causing the problem, but pip.

Also, if you look at pip 20.3.4 – PyPI, it seems that Python 2.7/3.5 is supported up to this version, and just recently (January 23, 2021), both were released on the same day, the 21.0 series which only supports Python 3.6 and later, and the 20.3 series which also supports Python 2.7/3.5. Both were released on the same day.

Release history – pip – PyPI[enter link description here][1]

If your pip has already been upgraded to 21.x, you may not be able to use that module no matter what you do, but you can try several ways to lower the pip version number.

Reinstall pip itself with the old version number up to 20.3.4. Install pip for Python 3.5 using the method introduced by @metropolis Create a new Python 3.5.1 environment and install pip for Python 3.5 in it.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement