Reputation: 2271
I tried to install Ray, but it gave an error:
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).
I tried to solve the problem and downgraded protobuf:
Name: protobuf
Version: 3.20.0
Summary: Protocol Buffers
Home-page: https://developers.google.com/protocol-buffers/
Author:
Author-email:
License: BSD-3-Clause
Location: d:\opencv\lib\site-packages
Requires:
Required-by: ray, tensorboard, tensorflow
But still the problem persists in Ray, TensorFlow, and Keras. My application isn't working any more. How can I fix it?
Upvotes: 222
Views: 370871
Reputation: 479
Solution 1: Downgrade Protobuf
This library has recently released a new version, which causes an error. Use this command in the terminal to downgrade, which should resolve the problem:
pip install --upgrade "protobuf<=3.20.1"
Or force a reinstallation of an older version:
pip install 'protobuf<=3.20.1' --force-reinstall
Solution 2: Update TensorFlow to the latest version
TensorFlow 2.9.1 was released on 23 May 2022. It can be updated like so:
pip install tensorflow==2.9.1
Always use the latest version of TensorFlow.
Upvotes: 38
Reputation: 39012
I recently saw this same error in my code. In my case there was also a stack trace that implicated pychromecast
. So, for me, the fix was just an update of the pychromecast
package. It is just a reminder that the fix may not necessarily be a downgrade of some package.
Upvotes: 0
Reputation: 7919
What did it for me was updating TensorFlow from version 2.5.0 to 2.12.
Upvotes: 0
Reputation: 71
The following worked for me in TensorFlow 2.8:
pip install protobuf==3.20.*
Upvotes: 5
Reputation: 1
I had a very simple solution to this exact problem when downgrading Protocol Buffers didn’t work (and I didn’t want to risk reducing program performance). I encountered this problem when running a notebook in Visual Studio Code.
My solution was to open Visual Studio Code as an administrator via CMD.
Upvotes: 0
Reputation: 11
I am using TensorFlow 1.15.5 and Python 3.7.9.
These particular versions helped for me:
wandb 0.12.17
protobuf 3.15.0
You can use:
pip install wandb==0.12.17
pip uninstall protobuf
pip install protobuf==3.15.0
Upvotes: 1
Reputation: 16
I had the same problem with streamlit.
OLD-> streamlit==1.19.0
I updated the version of streamlit using
pip install streamlit --upgrade
and it worked.
New -> streamlit==1.23.1
Upvotes: 0
Reputation: 1
I was able to solve a similar problem by uninstalling Protocol Buffers using pip and then installing an older version (3.20.1) of the package using Conda.
pip uninstall protobuf
conda install 'protobuf=3.20.1'
Upvotes: 0
Reputation: 21
I had a similar issue. In my case, I simply verified my Python interpreter to be sure Protocol Buffers (3.20.3) is installed into the interpreter, which was not the case, although it was installed on the virtual environment created for the project.
Upvotes: 0
Reputation: 385
The command
pip install protobuf==3.20.3 --upgrade
Worked for me. All other versions mentioned in the answers did not solve the problem.
Upvotes: 6
Reputation: 11
I had the same issue after upgrading Google Cloud logging.
I solved it upgrading google-cloud-audit-log:
pip install google-cloud-audit-log==0.2.4
Working versions:
pip freeze | grep google
google-api-core==2.10.2
google-api-python-client==2.57.0
google-auth==2.10.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.5.2
google-cloud-appengine-logging==1.1.6
google-cloud-audit-log==0.2.4
google-cloud-core==2.3.2
google-cloud-logging==3.2.5
google-cloud-storage==2.5.0
google-crc32c==1.1.2
google-resumable-media==2.4.0
googleapis-common-protos==1.56.4
grpc-google-iam-v1==0.12.4
Upvotes: 1
Reputation: 175
Even I came across the same error.
I solved it by installing protobuf:
pip install protobuf==3.20.
Upvotes: 13
Reputation: 760
I found the same problem, but I followed the instructions on this web page:
Python Packaging User Guide (on GitHub)
sphinx 4.3.1
sphinx-autobuild 0.7.1
sphinx-inline-tabs 2021.4.11b9
python-docs-theme 2021.5
sphinx-copybutton 0.4.0
Output of python -V
:
Python 3.8.10
Output of protoc.exe --version
:
libprotoc 3.21.0-rc2
pip install git+https://github.com/pypa/pypa-docs-theme.git#egg=pypa-docs-theme
Compile libraries
Copy the compiled library from F:\temp\Python\protoc\packaging.python.org\protobuf\Debug to F:\temp\Python\protoc\packaging.python.org\protobuf\src
Output:
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build\lib.win-amd64-3.8
creating build\lib.win-amd64-3.8\google
copying google\__init__.py -> build\lib.win-amd64-3.8\google
creating build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\any_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\api_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\descriptor.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\descriptor_database.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\descriptor_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\descriptor_pool.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\duration_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\empty_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\field_mask_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\json_format.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\message.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\message_factory.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\proto_builder.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\reflection.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\service.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\service_reflection.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\source_context_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\struct_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\symbol_database.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\text_encoding.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\text_format.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\timestamp_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\type_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\unknown_fields.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\wrappers_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\__init__.py -> build\lib.win-amd64-3.8\google\protobuf
...
testTimestampSerializeAndParse (google.protobuf.internal.well_known_types_test.TimeUtilTest) ... ok
testTimezoneAwareDatetimeConversionLA (google.protobuf.internal.well_known_types_test.TimeUtilTest)
testTimezoneAwareDatetimeConversionLA([1969, 12, 31, 18], datetime.timezone(datetime.timedelta(days=-1, seconds=57600), 'US/Pacific')) ... ok
testTimezoneAwareDatetimeConversionLondon (google.protobuf.internal.well_known_types_test.TimeUtilTest)
testTimezoneAwareDatetimeConversionLondon([1970, 1, 1, 2], datetime.timezone.utc) ... ok
testTimezoneAwareDatetimeConversionTokyo (google.protobuf.internal.well_known_types_test.TimeUtilTest)
testTimezoneAwareDatetimeConversionTokyo([1970, 1, 1, 11], datetime.timezone(datetime.timedelta(seconds=32400), 'Japan')) ... ok
testTimezoneNaiveDatetimeConversion (google.protobuf.internal.well_known_types_test.TimeUtilTest) ... ok
testByteSizeFunctions (google.protobuf.internal.wire_format_test.WireFormatTest) ... ok
testPackTag (google.protobuf.internal.wire_format_test.WireFormatTest) ... ok
testUnpackTag (google.protobuf.internal.wire_format_test.WireFormatTest) ... ok
testZigZagDecode (google.protobuf.internal.wire_format_test.WireFormatTest) ... ok
testZigZagEncode (google.protobuf.internal.wire_format_test.WireFormatTest) ... ok
Upvotes: 1
Reputation: 77
Descriptors cannot not be created directly:
Upvotes: 4
Reputation: 57
Alternatively, I was able to upgrade to wandb==0.12.17
, and everything seems to be working.
Old (not working):
- pip:
- wandb==0.10.21
New (working):
- pip:
- wandb==0.12.17
Upvotes: 4
Reputation: 8566
Sometimes the protobuf package might be installed without your involvement. For this, you have two solutions to apply. Try one of the below solutions and it should work.
You can downgrade the protobuf plugin,
pip install protobuf==3.20.*
Or you can add it to the requirements.txt
file as the last package. Because this will override the previously installed protobuf package.
...
protobuf==3.20.*
You can set the following environment variable.
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
according to the error description, this might impact your program performance.
but this will use pure-Python parsing and will be much slower
References:
Upvotes: 267
Reputation: 181
In my case I did not have protobuf
explicitly in my requirements.txt
file, but I did have a related dependency which was apparently problematic:
googleapis-common-protos==1.6.0 # Depends on protobuf
Removing this allowed the subsequent pip install -e .
(assuming setup.py
is present) to go with whatever google-api-core==1.13.0
had for dependencies. That resulted in the installation of googleapis-common-protos==1.56.2
and resolved the error.
Upvotes: 13