I am unable to get tensorflow to execute - python-3.x

The following is a snippet from my Python 3.5 interpreter. I don't understand why this produces the error (Listed bellow). Any suggestions?
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64
bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, Tensorflow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Then it gives me just a list of internal Errors starting with:
E c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:943]

Related

What does platform.system() and platform.architecture() return on Apple M1 Silicon?

I don't have an M1 Mac to work with, I read that python supports it. What's the return of these functions on m1 Macs?
platform.system()
platform.architecture()
Thanks.
On the actual M1 Mac, the platform module returns the following values:
shuuji3#momo ~ % python3
Python 3.8.2 (default, Dec 21 2020, 15:06:03)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'macOS-11.2.3-arm64-arm-64bit'
>>> platform.system()
'Darwin'
>>> platform.architecture()
('64bit', '')
>>> platform.processor()
'arm'
In addition to that, under the Rosetta 2 (Intel mode), the platform module returns the different values like followings:
shuuji3#momo ~ % env /usr/bin/arch -x86_64 /bin/zsh --login
shuuji3#momo ~ % python3
Python 3.8.2 (default, Dec 21 2020, 15:06:04)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'macOS-11.2.3-x86_64-i386-64bit'
>>> platform.system()
'Darwin'
>>> platform.architecture()
('64bit', '')
>>> platform.processor()
'i386'
Note: For the first command, I'm following the instruction in the article, How to Run Legacy Command Line Apps on Apple Silicon | Walled Garden Farmers.
We could use these values to distinguish under which mode the current M1 mac runs an application.
I got an M1 pro and the outputs are:
Python 3.8.15 (default, Nov 10 2022, 13:17:42)
[Clang 14.0.6 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more
information.
>>> import platform
>>> platform.platform()
'macOS-10.16-x86_64-i386-64bit'
>>> platform.system()
'Darwin'

Why parse_qsl does not work for empty value?

I don't quite understand why no results are returned when the value is empty. Is there a way to get the key value pair when the value is empty? Thanks.
>>> urllib.parse.parse_qsl('a=b')
[('a', 'b')]
>>> urllib.parse.parse_qsl('a=')
[]
You can use keep_blank_values parameter. By the way, what version of python are you using. This is what I get when I use the keep_blank_values. By default it is set to False. And I use python version 3.8.2
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.parse import parse_qsl
>>> parse_qsl('a=b')
[('a', 'b')]
>>> parse_qsl('a=')
[]
>>> parse_qsl('a=', keep_blank_values=True)
[('a', '')]
>>>

LoadImage in podman with python3

I'm trying to load my tar image in podman.
Python 3.7.8 (default, Jun 29 2020, 05:46:05)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import podman
>>> c = podman.Client(uri='unix://var/run/docker.sock') #docker.sock is my mount point for podman socket
>>> c.
c.containers c.images c.pods c.system
>>> c.images.
c.images.build( c.images.get( c.images.list( c.images.search(
c.images.delete_unused( c.images.import_image( c.images.pull(
>>> c.images.
I don't see any load image method.
Is there any method like c.load_image("/tmp/se.tgz")? similar method exists for docker and easily doable.
There is an existing API that can be used like this.
c = podman.Client(uri='unix://var/run/docker.sock')
with c._client() as podman:
results = podman.LoadImage("", "/tmp/se.tgz", False, False)

How to process the ASCII in Python3.65?

there is a log file to process, which comes from a machine of the other company.
They are using Python2.7, so the file is encoded by ASCII. But in my team, we are using Python3.65.
When I
fileopen = open(my_file, 'rb')
file_content = fileopen.read()
I find the file_content is automatically decoded by UTF-8.How to handle this?
What you are seeing is an artifact of the way your editor is displaying the data. If you read a file in binary you will get the same bytes you wrote. They are are just bytes, not encoded as anything. Your editor looks like it is decoding the string for display...incorrectly.
Below I write a file in binary with Python 3.6 and read it back with 2.7 and 3.6:
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> open('test.txt','wb').write(b'\x8c\x8d\x91\x8c')
4
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> open('test.txt','rb').read()
'\x8c\x8d\x91\x8c'
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> open('test.txt','rb').read()
b'\x8c\x8d\x91\x8c'
In both cases the same four bytes read are the ones written.
Try displaying the value of the bytes instead of the strings:
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> b = open('test.txt','rb').read()
>>> for c in b:
... print(hex(c))
...
0x8c
0x8d
0x91
0x8c
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> b = open('test.txt','rb').read()
>>> for c in b:
... print hex(ord(c))
...
0x8c
0x8d
0x91
0x8c

Why do strings returned by TensorFlow show up with a 'b' prefix in Python 3?

I just finished installing Tensorflow 1.3 on RPi 3. When validating the installation (according to this https://www.tensorflow.org/install/install_sources) somehow a lowercase "b" shown up. See these codes:
root#raspberrypi:/home/pi# python
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>>
No, it's not a bug. Your installation is perfectly fine, this is the normal behavior.
The b before the string is due to the Tensorflow internal representation of strings.
Tensorflow represents strings as byte array, thus when you "extract" them (from the graph, thus tensorflow's internal representation, to the python enviroment) using sess.run(hello) you get a bytes type and not a str type.
You can verify this using the type function:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(type(sess.run(hello)))
results in <class 'bytes'> whilst if you do:
print(type('Hello, TensorFlow!'))
results in <class 'str'>

Resources