ansys / pymechanical

Pythonic interface to Ansys Mechanical ™
https://mechanical.docs.pyansys.com/
MIT License
36 stars 18 forks source link

PIM causes a protobuf version mismatch #70

Closed koubaa closed 12 months ago

koubaa commented 1 year ago

To reproduce, simply try to install this package and use it.

You will get this error:

>>> import ansys.mechanical.core
CRITICAL -  -  logging - handle_exception - Uncaught exception
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\AnsysDev\NoBackup\code\pyansys\test\lib\site-packages\ansys\mechanical\core\__init__.py", line 11, in <module>
    from ansys.mechanical.core.mechanical import (
  File "C:\AnsysDev\NoBackup\code\pyansys\test\lib\site-packages\ansys\mechanical\core\mechanical.py", line 17, in <module>
    import ansys.platform.instancemanagement as pypim
  File "C:\AnsysDev\NoBackup\code\pyansys\test\lib\site-packages\ansys\platform\instancemanagement\__init__.py", line 10, in <module>
    from ansys.platform.instancemanagement.client import Client
  File "C:\AnsysDev\NoBackup\code\pyansys\test\lib\site-packages\ansys\platform\instancemanagement\client.py", line 7, in <module>
    from ansys.api.platform.instancemanagement.v1.product_instance_manager_pb2 import (
  File "C:\AnsysDev\NoBackup\code\pyansys\test\lib\site-packages\ansys\api\platform\instancemanagement\v1\product_instance_manager_pb2.py", line 18, in <module>
    from protoc_gen_swagger.options import annotations_pb2 as protoc__gen__swagger_dot_options_dot_annotations__pb2
  File "C:\AnsysDev\NoBackup\code\pyansys\test\lib\site-packages\protoc_gen_swagger\options\annotations_pb2.py", line 16, in <module>
    from protoc_gen_swagger.options import openapiv2_pb2 as protoc__gen__swagger_dot_options_dot_openapiv2__pb2
  File "C:\AnsysDev\NoBackup\code\pyansys\test\lib\site-packages\protoc_gen_swagger\options\openapiv2_pb2.py", line 35, in <module>
    _descriptor.EnumValueDescriptor(
  File "C:\AnsysDev\NoBackup\code\pyansys\test\lib\site-packages\google\protobuf\descriptor.py", line 755, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
koubaa commented 1 year ago

Fixed if I uninstall protobuf latest and instead install 3.18 (for instance). This error should be fixed in pim so that the latest protobuf can be used

koubaa commented 1 year ago

pinging @plule-ansys

plule-ansys commented 1 year ago

@koubaa Hello, sorry this message happened just as I went out on vacation. I'm quite surprised about this since pypim correctly declares its incompatibility with the recent protobuf. Its exact require is "protobuf~=3.13" that prevents to go to 4.x.

{plule@lyoub22fwtst01}{/home/plule}$ python -m venv test-pypim
{plule@lyoub22fwtst01}{/home/plule}$ source test-pypim/bin/activate
(test-pypim) {plule@lyoub22fwtst01}{/home/plule}$ pip install ansys-platform-instancemanagement pipdeptree
<snip>
Successfully installed ansys-api-platform-instancemanagement-1.0.0b3 ansys-platform-instancemanagement-1.0.2 googleapis-common-protos-1.57.0 grpcio-1.51.1 importlib-metadata-6.0.0 pipdeptree-2.3.3 protobuf-3.20.3 protoc-gen-swagger-0.1.0 zipp-3.11.0
(test-pypim) {plule@lyoub22fwtst01}{/home/plule}$ pipdeptree
ansys-platform-instancemanagement==1.0.2
  - ansys-api-platform-instancemanagement [required: >=1.0.0b3, installed: 1.0.0b3]
    - googleapis-common-protos [required: Any, installed: 1.57.0]
      - protobuf [required: >=3.19.5,<5.0.0dev,!=4.21.5,!=4.21.4,!=4.21.3,!=4.21.2,!=4.21.1,!=3.20.1,!=3.20.0, installed: 3.20.3]
    - grpcio [required: Any, installed: 1.51.1]
    - protobuf [required: ~=3.13, installed: 3.20.3]
    - protoc-gen-swagger [required: Any, installed: 0.1.0]
      - protobuf [required: >=3.0.0, installed: 3.20.3]
  - importlib-metadata [required: >=4.0, installed: 6.0.0]
    - zipp [required: >=0.5, installed: 3.11.0]
pip==22.0.2
pipdeptree==2.3.3
setuptools==59.6.0

In fact, even pymechanical should prevent you to end up with the 4.x protobuf package, it declares: "protobuf>=3.12.2,<3.21.0" in the pyproject toml.

I also tried to first install protobuf, which installed 4.21.12, then pypim, and it correctly downgraded protobuf to a compatible version, so I'm not sure how you could have both pymechanical and protobuf 4.x...

Side note, we do have an identified task to upgrade the generated code and be compatible with protobuf 4.x.

koubaa commented 1 year ago

@plule-ansys I added the version range to pyproject.toml after encountering this bug! But I don't close this bug because I don't like to restrict the version like this.

Please let me know once you've fixed that issue in pypim and I will remove the range here.

plule-ansys commented 1 year ago

@koubaa

I added the version range to pyproject.toml after encountering this bug!

Oh ok it makes sense thank you.

There is still no reason why you need this change though, the constraint is already set in pypim, can you please provide a more detailed reproduction?

Here is what I've been doing:

  1. Remove the protobuf entry from pymechanical's pyproject.toml
  2. :
{plule@lyoub22fwtst01}{/home/plule/pyansys/pymechanical}$ python -m venv .venv
{plule@lyoub22fwtst01}{/home/plule/pyansys/pymechanical}$ source /home/plule/pyansys/pymechanical/.venv/bin/activate
(.venv) {plule@lyoub22fwtst01}{/home/plule/pyansys/pymechanical}$ pip install -e .
Obtaining file:///home/plule/pyansys/pymechanical
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Collecting ansys-platform-instancemanagement>=1.0.1
  Using cached ansys_platform_instancemanagement-1.0.2-py3-none-any.whl (16 kB)
Collecting ansys-pythonnet==3.1.0rc1
  Using cached ansys_pythonnet-3.1.0rc1-py3-none-any.whl (282 kB)
Collecting tqdm>=4.45.0
  Using cached tqdm-4.64.1-py2.py3-none-any.whl (78 kB)
Collecting grpcio<=1.51.1,>=1.30.0
  Using cached grpcio-1.51.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.8 MB)
Collecting appdirs>=1.4.0
  Using cached appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB)
Collecting importlib-metadata>=4.0
  Using cached importlib_metadata-6.0.0-py3-none-any.whl (21 kB)
Collecting clr-loader<0.3.0,>=0.2.5
  Using cached clr_loader-0.2.5-py3-none-any.whl (51 kB)
Collecting ansys-api-platform-instancemanagement>=1.0.0b3
  Using cached ansys_api_platform_instancemanagement-1.0.0b3-py3-none-any.whl (6.6 kB)
Collecting zipp>=0.5
  Using cached zipp-3.11.0-py3-none-any.whl (6.6 kB)
Collecting protoc-gen-swagger
  Using cached protoc_gen_swagger-0.1.0-py2.py3-none-any.whl (9.4 kB)
Collecting protobuf~=3.13
  Using cached protobuf-3.20.3-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.1 MB)
Collecting googleapis-common-protos
  Using cached googleapis_common_protos-1.57.1-py2.py3-none-any.whl (218 kB)
Collecting cffi>=1.13
  Using cached cffi-1.15.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (441 kB)
Collecting pycparser
  Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
Building wheels for collected packages: ansys-mechanical-core
  Building editable for ansys-mechanical-core (pyproject.toml) ... done
  Created wheel for ansys-mechanical-core: filename=ansys_mechanical_core-0.7.dev2-py3-none-any.whl size=4806 sha256=c7e24a8a8ae2c61abb71114ae91668e8b226c8cdff212f43eef216cfe4a181bc
  Stored in directory: /tmp/pip-ephem-wheel-cache-3api65yp/wheels/c4/74/35/4bfc844ad4d5d93e2df3993dbed75622615a9c6706150485ed
Successfully built ansys-mechanical-core
Installing collected packages: appdirs, zipp, tqdm, pycparser, protobuf, grpcio, protoc-gen-swagger, importlib-metadata, googleapis-common-protos, cffi, clr-loader, ansys-api-platform-instancemanagement, ansys-pythonnet, ansys-platform-instancemanagement, ansys-mechanical-core
Successfully installed ansys-api-platform-instancemanagement-1.0.0b3 ansys-mechanical-core-0.7.dev2 ansys-platform-instancemanagement-1.0.2 ansys-pythonnet-3.1.0rc1 appdirs-1.4.4 cffi-1.15.1 clr-loader-0.2.5 googleapis-common-protos-1.57.1 grpcio-1.51.1 importlib-metadata-6.0.0 protobuf-3.20.3 protoc-gen-swagger-0.1.0 pycparser-2.21 tqdm-4.64.1 zipp-3.11.0
(.venv) {plule@lyoub22fwtst01}{/home/plule/pyansys/pymechanical}$ python
Python 3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ansys.mechanical.core
>>>