Linux uses pyinstaller to package tensorflow's python code into executable files

pyinstaller can easily package python code into executable files.




1. Install pyinstaller-


Bash code
1
sudo pip install pyinstaller After
installation, you can use the following command to check the pyinstaller version


-Bash code
1
pyinstaller --version


2. Write python code test.py, such as




-Python code
1
import numpy as np
2
 
3
if __name__ == "__main__":
4
    a = np.array([1,2,3])
5
    b = np.array([4,5,6])
6
    print a+b


3. Use pyinstaller to copy the code Packaged


in the code directory, enter
-Bash code
1
pyinstaller test.py
will generate two folders build and dist in the current directory, and a file test.spec


in which dist contains the executable file test, you can run it directly




4. Write a python code that uses tensorflow and save it as test.py


-Python code
01
import numpy as np
02
import tensorflow as tf
03
 
04
if __name__ == "__main__":
05
        a = np.array([1,2,3,4])
06
        b = np.array([5,6,7 ,8])
07
        print a+b
08
 
09
        node1 = tf.constant(3.0, dtype=tf.float32)
10
        node2 = tf.constant(4.0) # also tf.float32 implicitly
11
        print(node1, node2)
12
 
13
        sess = tf.Session()
14
        print(sess.run([node1, node2]))


and then package it into an executable file according to step 3, but the following error will be reported when running


xception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name mock was given, but was not able to be found.
[1799] Failed to execute script test


This error, how to solve it?




The search yielded two solutions (refer to https://github.com/pyinstaller/pyinstaller/issues/2883):
1. In the python program, add the following statement:


-Html code
view code
1
import os
2
 
3
os. environ["PBR_VERSION"]='3.1.1' #The version number can be viewed with pbr -v,
but this method doesn't seem to work well in linux, but it seems to be useful on MAC OS


2. Add in /etc/environment
-Python code
1
PBR_VERSION=3.1.1
and then close the current vim, it will be valid after restarting vim, and it will be ok to run again

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324518896&siteId=291194637