AttributeError: module 'tensorflow._api.v2.summary' has no attribute 'image' - windows

I have installed Tensorflow on Windows 10 Pro in a Anaconda environment. When I try to use the tf.summary API, I systematically get AttributeError:
python --version
Python 3.8.12
python
>>> import tensorflow as tf
2022-03-30 09:09:03.938282: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-03-30 09:09:03.939342: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
C:\Users\JohnDoe\Anaconda3\envs\tfenv\lib\site-packages\numpy\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:
C:\Users\JohnDoe\Anaconda3\envs\tfenv\lib\site-packages\numpy\.libs\libopenblas.EL2C6PLE4ZYW3ECEVIV3OXXGRN2NRFM2.gfortran-win_amd64.dll
C:\Users\JohnDoe\Anaconda3\envs\tfenv\lib\site-packages\numpy\.libs\libopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
warnings.warn("loaded more than 1 DLL from .libs:"
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.
>>> print(tf.__version__)
2.8.0
>>> dir(tf.summary)
['SummaryWriter', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_sys', 'create_file_writer', 'create_noop_writer', 'experimental', 'flush', 'graph', 'record_if', 'should_record_summaries', 'trace_export', 'trace_off', 'trace_on', 'write']
>>> tf.summary.image()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow._api.v2.summary' has no attribute 'image'
>>> tf.summary.scalar()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow._api.v2.summary' has no attribute 'scalar'
According to the doc, image and scalar are attributes of tf.summary in TF2.8. Is this error specifically related to Windows? I am using Anaconda to manage my environment, but TF was installed with PIP.

I solved the issue by forcing the reinstallation of tensorboard:
pip install --force --no-deps tensorboard
It worked like perfectly after that.

Related

Python 3.6 - Tensorflow DLL load failed when importing tensorflow

I installed Tensorflow on my command prompt using pip3 on Python 3.6 using:
pip3 install tensorflow==1.5
When checking if I could import tensorflow off the terminal using Python I got the following error message:
Python 3.6.0rc2 (v3.6.0rc2:800a67f7806d, Dec 16 2016, 23:22:07) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\{User}\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Users\{User}\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Users\{User}\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "C:\Users\{User}\AppData\Local\Programs\Python\Python36\lib\site-packages\google\protobuf\descriptor.py", line 47, in <module>
from google.protobuf.pyext import _message
ImportError: DLL load failed: The specified procedure could not be found.
What exactly is missing from the DLL?
Are there any issues when installing? Also, why are you installing tensorflow 1.5 when 1.9 is available? I would first try pip uninstall tensorflow and then pip install tensorflow. If you still have issues I would try going here to download the .whl file and then you can do pip install [whatever the filename is].whl. Directly installing these .whl files has solved many a problem for me.
To answer your question, it looks like you are missing descriptor.py from google protobuf. You could try downloading that and moving descriptor.py directly, but my guess is if it can't find one file it's probably missing other things as well.
Looking at other problems with tensorflow imports, it looks like the problem is compatibility with python 3.6 having a divergent path with pip, however it looks like this was solved at some point in the last year. If you're still stuck, of course try upgrading pip, python, and tensorflow; then try downgrading to python 3.5 to see if that works. Best of luck!
Change the protobuf version to pip install protobuf==3.6.0

How to import leveldb in Python 3.5 on Windows

I struggled a while to install leveldb package in Python 3.5 on Windows.
https://github.com/happynear/py-leveldb-windows gives some clues on how to install the package. However, even though following all the instruction in the post, I still got a following error when I imported the package leveldb in Ipython prompt:
import leveldb
Traceback (most recent call last):
File "<ipython-input-16-4427bf69c6fb>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
Does anyone know how to solve this problem?
The compiled pyd file at https://github.com/happynear/py-leveldb-windows is for Python 3.6 as of 18.03.2019. I had the same error as the OP when trying to use it with Python 3.7. Uninstalling 3.7 and installing 3.6 made it work.

AttributeError: module 'lightgbm' has no attribute 'LGBMClassifier'

I installed lightgbm with conda install -c creditx lightgbm=0.2.0,and import lightgbm success, but when I import LGBMClassifier or using LGBMClassifier it fails.
Error is:
<module 'posixpath' from '/usr/anaconda3/lib/python3.5/posixpath.py'>
Traceback (most recent call last):
File "/root/Final_Contest/ligGBM.py", line 12, in <module>
gbm = lgb.LGBMClassifier(objective='binary',num_leaves=31,learning_rate=0.1,n_estimators=3000)
AttributeError: module 'lightgbm' has no attribute 'LGBMClassifier'
What could be the case?
I removed the graphviz and lightgbm package from Anaconda Prompt and installed the libraries using conda install.
It worked for me.

Scipy installation windows 10

I have some difficulties trying to install Scipy for Python 3.5 on a Windows 10 machine and I hope I can find some help here. So here is what I have done so far.
I have downloaded the numpy+mkl for python 3.5 and 64bit version as well as the scipy0.18.1 for the same versions, from Gohlke's website
I installed the numpy+mkl whl with:
python -m pip install numpy-1.11.2+mkl-cp35-cp35m-win_amd64.whl
all goes well.
then I install the scipy package the same way like:
python -m pip install scipy-0.18.1-cp35-cp35m-win_amd64.whl
This also completes.
However, when I try to run python afterwards I get the following error:
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
File "C:\Python35\Lib\site-packages\scipy\io\__init__.py" , line 97, in <module>
File "C:\Python35\Lib\site-packages\scipy\io\matlab\__init__.py", line 13 in <module>
File "C:\Python35\Lib\site-packages\scipy\io\matlab\mio.py", line 8 in <module>
ImportError: No module named 'numpy'
I also get a pop-up that Python has stopped working.
I have tried a different order in which I installed the packages, but all lead to the error mentioned when Scipy is installed.
I also installed did this on a windows 7 machine and there it works.
Does anybody have any idea what causes this issue?
I also had some issues. So I just installed Anaconda3 insted of python directly.

MySQL-Python with PyPy

MySQL-Python (MySQLdb) is known to work with PyPy. How do you make it work?
I tried downloading it and installing:
C:\dev\Installs\MySQL-python\MySQL-python-1.2.3>pypy setup.py install
Traceback (most recent call last):
File "app_main.py", line 51, in run_toplevel
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "C:\dev\Installs\MySQL-python\MySQL-python-1.2.3\setup_windows.py", line 7, in get_config
serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options['registry_key'])
WindowsError: [Error 2] The system cannot find the file specified.
Then I tried to download the ctypes implementation which seemed to have installed ok, however trying to use it gave:
...
File "C:\pypy-1.7\site-packages\django\db\backends\mysql\base.py", line 14, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: Can't find a libmysqlclient
I'm at a loss at this point. How do I make it work
Regarding your second error with mysql-ctypes, the answer is that the line
ctypes.util.find_library('mysqlclient')
can't find the library on windows. Changing it to:
ctypes.util.find_library('mysqlclient.lib')
works on my system - but that only gets you to the next error (windows error 193) on my system.
you're right, the original MySQLdb is known to not work on PyPy.
I never tried to install mysql-ctypes on a windows maschine as I do not have one, but do you have libmysqlclient installed in your PATH?
If so, you may try my (sadly not yet merged) fork on https://github.com/EnTeQuAk/mysql-ctypes which has support for a bit more versions of libmysqlclient.
I had no issues with the MySQLdb package in pypy after installing it using pip.
You can find instructions for installing pip for pypy in the second section of the following link: http://doc.pypy.org/en/latest/getting-started.html#installing-pypy
Once you have pip installed, it's just a matter of running
pip install MySQL-python

Resources