From 7250d059e1dba3c9675331d1c6001bba9e1d718f Mon Sep 17 00:00:00 2001 From: Terry J Fundak Date: Sun, 17 Jan 2016 14:31:43 -0800 Subject: [PATCH] Add a pyenv .python-version file and addition rational to README>md --- .python-version | 1 + README.md | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .python-version diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..bec3a35 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +system diff --git a/README.md b/README.md index e69de29..1206c20 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,31 @@ +Note for Developer mostly... + +The group of Admin Scripts written in python2 and use an Apple specific python module called Foundation. +If you encounter a speed bump where the Foundation module can not be imported, +then the issue may be that you are not using default Apple python. + +For example, if you happen to use pyenv to manage your python environment then +you might encounter a runtime error like this: + +>sudo python check-if-virtual-machine.py +Traceback (most recent call last): + File "check-if-virtual-machine.py", line 25, in + from Foundation import CFPreferencesCopyAppValue +ImportError: No module named Foundation + + i.e. to set the python version you are using, +then all that is needed is to point to the system install python to avoid the follow import error + +>pyenv local system + +This command will create/modify the python used +and create a .python-version file with contents "system" to point to the system python and the above error goes away. + +Another possible solution is to change #! at the start of the script from +#!/usr/bin/env python +to use the system python +#!/usr/bin/python + +Since all these python scripts are targeted for use with Apple systems, +and are dependent on the Foundation module, +the path of least resistance for me was to use pyenv switch but for more non-developer systems, this may not matter.