To set the environment prior to the execution of python3, invoke:
eval `pythonenv`
This command is *only* to be used to prepare the environment to execute Python3 scripts in "Recovery Script" trees.
When writing Python3 scripts for WA2L/edrc, do *not* use pythonenv, start the script thru the .python_wrapper. See python_wrapper(1) for information about integrating a Python3 script into WA2L/edrc.
Where <major> is the major version number (e.g. 3) and <minor> is the minor Python3 version (e.g. 6).
To start a Python3 script that uses a bundled Python3 module from a recovery script, set the Python3 environment using the 'eval `pythonenv`' command in the recovery script and then call the python3 interpreter.
Recovery script:
#!/bin/ksh # # 1:ascript - A Recovery Script # # [00] 08.02.2009 CWa Initial Version # # test "$DEBUG" = True && set -x : : eval `pythonenv` python3 ./pythonscript :
Python3 script:
# # pythonscript - Python3 script using bundled complex module # # [00] 18.03.2009 CWa Initial Version # : : from complex import Complex :
Create an _env file (using the env edrc command) and start the Python3 script from the recovery script.
_env file:
# # _env - Environment settings for commands in /apps/eg # # [00] 18.03.2009 CWa Initial Version # # test "$DEBUG" = True && set -x eval `pythonenv` :
Recovery script:
#!/bin/ksh # # 1:ascript - A Recovery Script # # [00] 08.02.2009 CWa Initial Version # # test "$DEBUG" = True && set -x : : python3 ./pythonscript :
Python3 script:
# # pythonscript - Python3 script using bundled complex module # # [00] 18.03.2009 CWa Initial Version # : : from complex import Complex :
Create an _env file (using the env edrc command) and write the recovery script in Python3.
_env file:
# # _env - Environment settings for commands in /apps/eg # # [00] 18.03.2009 CWa Initial Version # # test "$DEBUG" = True && set -x eval `pythonenv` :
Python3 recovery script:
#!/usr/bin/env python3 # # 1:ascript - A Recovery Script # # [00] 08.02.2009 CWa Initial Version # : : from complex import Complex :
Note the use of '#!/usr/bin/env python3' in the magic key to start the Python3 script. This ensures that the python3 interpreter is found on the system, even when it is not installed in the default location you will normally specify. The path to the python3 interpreter is added to the $PATH using the pythonenv command.
The startup method method below allows to start the python3 interpreter from wherever it is installed and also enables to use all python3 packages/modules bundled with WA2L/edrc using the pythonenv command to dynamically initialize the environment.
This method is similar to the use of the .python_wrapper, but the Python3 script can be placed somewhere of your liking outside of WA2L/edrc.
Set the permissions of the script to executable:
chmod +x pythonscript
Python3 script:
#!/bin/ksh # # pythonscript - Python3 script using bundled modules # # [00] 18.03.2009 CWa Initial Version # eval `~edrc/lib/pythonenv` sed '1,/^exit \$\?/d' $0 | python3 - "$0" "$@" exit $? # python # import sys from complex import Complex sys.argv[0] = sys.argv.pop(1); __file__ = sys.argv[0] def main(): print("Hello World!\n"); print("Arguments:", sys.argv[0:]) x = Complex(2,3) y = Complex(4,5) print("x+y = {}".format(x+y)) return(0) if __name__ == "__main__": sys.exit(main())
Set the needed python3 environment:
[ / ] [ root@acme007 ][*edrc*/bash]: eval `pythonenv`
Try to access the python3 module:
[ / ] [ root@acme007 ][*edrc*/bash]: python -c "import complex"
If an error message like
Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'complex'
appears, the package/module cannot be found, if the package/module can be found there is no output.
To list the installed Python3 packages, use the pip3(1) command.
To list the packages bundled in WA2L/edrc:
[ /opt/edrc/bin ] [ root@acme007 ][*edrc*/bash]: pip list --local
To list all packages available (this includes the packages/modules bundled in WA2L/edrc):
[ /opt/edrc/bin ] [ root@acme007 ][*edrc*/bash]: pip list
To list information about installed packages, the pip3(1) command is used.
The pip show [ --file ] packagename also displays the Location where the package is installed/read.
To show detail information of a package:
[ /opt/edrc/bin ] [ root@acme007 ][*edrc*/bash]: pip show complex
To show detail information and all installed files of a package:
[ /opt/edrc/bin ] [ root@acme007 ][*edrc*/bash]: pip show --file complex
This is free software; see edrc/doc/COPYING for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.