Invalid syntax on cryptography module

Hello,

I’m totally new on python (never too old to learn a new language…) and I met some difficulty around my project : I recovered an old project, written with python 2 and I try to upgrade it to python 3.
This will run on a SLES 12 SP5.

I’ve made some change (pip3 uses, syntax in python scripts) for being compatible with python 3, check the differents modules dependencies loaded (inquirer, paramiko, etc…) with last versions.
When I’m trying to run my scripts, I’ve this error:
File “install.py”, line 25, in
import postgresql
File “/tmp/my_project-4.2.16/data/postgresql.py”, line 12, in
import paramiko
File “./site-packages/paramiko/init.py”, line 22, in
from paramiko.transport import SecurityOptions, Transport
File “./site-packages/paramiko/transport.py”, line 33, in
from cryptography.hazmat.backends import default_backend
File “./site-packages/cryptography/hazmat/backends/init.py”, line 7
_default_backend: typing.Any = None
^
SyntaxError: invalid syntax

As this happens outside of my own script, I don’t see what can be wrong ?

That smells:

  1. you should not have modules on “/tmp” paths in your traceback
  2. I would be very surprised if the postgresql driver would import paramiko.

Remove this file after checking if you still need postgresql.py. If you still need it, move it to a permanent location and rename it.

What version of Python are you using?

You need Python 3.6 or better to support the syntax

_default_backend: typing.Any = None

Thanks for the quick answer !
In fact, I copied my project on the /tmp directory, trying to run its installation and so, modules are well in the /tmp paths.
“My” postgresql.py needs paramiko (this was working with it in python2, I’m trying to keep it for the moment)

Thanks also for the quick answer !
I’m using python3, not sure I can use python 3.6 : I tried but, in that case, I need the python36-curses package which is not provided by SUSE (only python3-curses available) :frowning:

Can you run

python3 --version

from your terminal or shell? We need to see the version.

If you have a version below 3.6, you need to either upgrade, or manually
downgrade the other library to remove all the variable annotations
causing errors.

Python 3.4.10

Is there any compatibility check when we install modules with pip ?
I tried a “pip3 install cryptography”, the last version is installed.

Recent versions of pip (9+) will skip versions of dependencies which don’t support your python version. I wonder if you’ve got a really old pip version.

Can you post the output of python3 -m pip --version?

I would, in any case, suggest upgrading to a newer Python version.

Thanks Dominic!
In fact, I have some constraints : final product should be installed on a SLES 12 SP5 and so, I’m not free to install any kind of version :frowning:

I just see an issue on my server : pip is linked to python3.6.
The ouput of your command shows me that there is no pip module linked to python3.4 but if I do same command with python3.6, I obtain the pip 21.1.2.

After analysis, I have access to python36-pip package through my SUSE account but I have no access to the repository where python3-pip is.

What is the impact of having pip running on python3.6 while I try to get modules compatible with python3.4 ? Does that means “*pip3 install --user cryptography==2.*8” will get the module specifically for python3.6 ?