Future Warning while importing tensorflow - python-3.x

I just started to learn tensorflow and happened to get through a Future Warning generated by the IPython console.
Here's the block of code:
import tensorflow as tf
x1 = tf.constant(4)
print(x1)
I saved it with the name "hello.py" and executed it on IPython console line by line.
The command gets executed successfully, but ends up with a warning.
Python 3.6.7 |Anaconda, Inc.| (default, Oct 28 2018, 19:44:12) [MSC v.1915 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 7.2.0 -- An enhanced Interactive Python.
In [1]: import tensorflow as tf
C:\Users\singh\Anaconda3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
In [2]: x1 = tf.constant(4)
In [3]: print(x1)
Tensor("Const:0", shape=(), dtype=int32)
I can't understand why am I getting this warning. Is there any way to fix this?
Tensorflow version: 1.10.2
Python IDE: Spyder (Anaconda)
OS: Windows 10 x64

use this command line
pip install h5py==2.8.0rc1
there maybe something wrong with package h5py,just upgrade it can solve your problem

Related

what does "NameError: name 'symbols' is not defined" mean?

This is my very first experience with sympy. I am usingDEbian bullseye with pythong. I installed git then "git clone https://github.com/sympy/sympy.git" Following that:
abraca#SS:~/SymPy$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import *
>>> x = symbols('x')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'symbols' is not defined
>>> quit()
What have I done wrong?
Here is what my tree looks like, starting from my root directory:
abraca#SS:~$ ls SymPy/sympy/sympy
abc.py core integrals polys tensor
algebras crypto interactive printing testing
assumptions diffgeom liealgebras release.py this.py
benchmarks discrete logic sandbox unify
calculus external matrices series utilities
categories functions multipledispatch sets vector
codegen galgebra.py ntheory simplify
combinatorics geometry parsing solvers
concrete holonomic physics stats
conftest.py __init__.py plotting strategies
Installing sympy via git never worked. Here is what did work (note the all important 3, placed after python, not pip):
sudo apt install python3-pip
pip3 install sympy
From then on it all works:
abraca#SS:~$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from sympy import *
>>> x=symbols('x')
>>> limit(sin(x)/x,x,0)
1
>>> quit()
abraca#SS:~$

Unable to import Pandas in IPython 6.5.0 console (Spyder)

After installing pandas am able to import in cmd as below :
C:\Users\me\Desktop\Django_Project>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>>
But when am importing pandas in Spyder in IPython 6.5.0 console I get below error:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 6.5.0 -- An enhanced Interactive Python.
c:\program files (x86)\python37-32\lib\site-packages\ipykernel\parentpoller.py:116: UserWarning: Parent poll failed. If the frontend dies,
the kernel may be left running. Please let us know
about your system (bitness, Python, etc.) at
ipython-dev#scipy.org
ipython-dev#scipy.org""")
In [1] : import pandas
Traceback (most recent call last):
File "<ipython-input-1-38d4b0363d82>", line 1, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
In [2] :
Note: I have installed python in "C:\Users\me\AppData\Local\Programs\Python\Python37\" path and environment variables is set as "C:\Users\me\AppData\Local\Programs\Python\Python37;"
And I installed pandas using PIP
Please suggest the solution to resolve this issue.I have tried reinstalling the pandas package almost 6-7 times.
I think you should open anaconda command prompt by searching it in windows search bar . Now write there "conda install -c anaconda pandas" and try again to run the program

I can't import Keras in Jupyter Notebook

When I run import keras in the Jupyter Notebook cell, it crashes with the following message:
The kernel appears to have died. It will restart automatically.
Keras 2.2.0
jupyter 1.0.0
jupyter-client 5.2.3
jupyter-console 5.2.0
jupyter-core 4.4.0
jupyterlab 0.32.1
jupyterlab-launcher 0.10.5
Python 3.6.6
Console import log
kraamis#debian [~]$ python3
Python 3.6.6 (default, Jun 27 2018, 14:44:17)
[GCC 8.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
/usr/lib/python3/dist-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
Using TensorFlow backend.
Illegal instruction
tensorflow 1.9.0
tensorflow-gpu 1.9.0
tensorflow-tensorboard 1.5.1
The problem was that my obsolete processor did not support AVX. It was necessary to install the version of tensorflow no older than 1.5

AttributeError: module 'tensorflow' has no attribute 'Graph'

I am writing the following code in Jupyter notebook.
import tensorflow as tf
g = tf.Graph()
And I encounter the following error while executing this simple code.
AttributeError: module 'tensorflow' has no attribute 'Graph'
If I execute the same from the console. It works. Any idea what's happening here.
More information:(test is my virtualenv)
ipython, jupyter, python version:
(test) xingzhou#xingzhou008:~/tensorflow$ which ipython3
/home/xingzhou/tensorflow/test/bin/ipython3
(test) xingzhou#xingzhou008:~/tensorflow$ which jupyter
/home/xingzhou/tensorflow/test/bin/jupyter
(test) xingzhou#xingzhou008:~/tensorflow$ which python3
/home/xingzhou/tensorflow/test/bin/python3
Execute from Console:
(test) xingzhou#xingzhou008:~/tensorflow$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> g = tf.Graph()
>>> type(g)
<class 'tensorflow.python.framework.ops.Graph'>
>>>
Make sure you haven't called any of your python files as 'tensorflow.py'
I resolved this issue by restarting Jupyter Notebook kernel. It's weird.
A simple solution worked for me.
From anaconda navigator first go to environments and create a tensorflow environment like this image
I named it tensorflow. Then from the right select all from the drop down menu and search for tensorflow.
Select it and hit apply. It will download some additional packages along with tensorflow. When you are done, select tensorflow from home and you should be good to go. Here it works.
Check if TensorFlow is installed in Anaconda/Environments. If not, just search and install. Then try to run g=tf.Graph() again. It worked for me.

How to print out member functions of a imported library in a python 3 console?

Note: The example output is an ipython (an enhanced python programming console) feature instead of a python 3 standard (#DTing). One can obtain a list of member functions by dir(libname) command when the default console is used (#Matthew Runchey).
In a python 2.7 console, one has the command libname. to print out member functions of an imported library libname .
The expected output should be something like:
>>> import hashlib
>>> hashlib.
hashlib.algorithms hashlib.new hashlib.sha224 hashlib.sha384
hashlib.md5 hashlib.sha1 hashlib.sha256 hashlib.sha512
(the example is taken from around 0:13 in this video: https://youtu.be/dG3tOsGEYP4 )
However, my python 3.4 console (Win7 x64) gave a syntax error.
>>> import hashlib
>>> hashlib.
File "<stdin>", line 1
hashlib.
^
SyntaxError: invalid syntax
So what is the correct way of doing the same thing in python 3?
dir(module_name)
This prints a list of the functions in whatever you imported.
>>>import hashlib
>>>dir(hashlib)
['__all__', '__builtin_constructor_cache', '__builtins__', '__cached__', '__doc__', '__file__', '__get_builtin_constructor', '__loader__', '__name__', '__package__', '__spec__', '_hashlib', 'algorithms_available', 'algorithms_guaranteed', 'md5', 'new', 'pbkdf2_hmac', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512']
That is not a feature of python, rather an ipython tab completion feature.
See below:
$ python
Python 2.7.9 (default, Apr 7 2015, 07:58:25)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import hashlib
>>> hashlib.
File "<stdin>", line 1
hashlib.
^
SyntaxError: invalid syntax
>>>
hitting tab after the .:
$ ipython
Python 2.7.9 (default, Apr 7 2015, 07:58:25)
Type "copyright", "credits" or "license" for more information.
IPython 3.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import hashlib
In [2]: hashlib.
hashlib.algorithms hashlib.md5 hashlib.sha1 hashlib.sha384
hashlib.algorithms_available hashlib.new hashlib.sha224 hashlib.sha512
hashlib.algorithms_guaranteed hashlib.pbkdf2_hmac hashlib.sha256
also works for python3:
$ ipython
Python 3.4.3 (default, Apr 7 2015, 08:05:21)
Type "copyright", "credits" or "license" for more information.
IPython 3.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import hashlib
In [2]: hashlib.
hashlib.algorithms_available hashlib.new hashlib.sha224 hashlib.sha512
hashlib.algorithms_guaranteed hashlib.pbkdf2_hmac hashlib.sha256
hashlib.md5 hashlib.sha1 hashlib.sha384
If you are using ipython, this might be a related issue IPython tab completion not working

Resources