Xcode Target Phase Python Script - iphone

I am trying to add a Python script to into my project to obtain the build and marketing numbers directly from Git.
I have created a new target phase and that runs a script as explained in:
http://yeahrightkeller.com/2008/10/19/xcode-run-script-build-phase-tip/
And I have written a Python script that parses the program Info.plist using
from Foundation import NSMutableDictionary
However the script fails while being compiled and reports the following error to the build results:
Running a custom build phase script: gitversion.py
Traceback (most recent call last):
File "/Users/jorge/Documents/Programming iPod/Pruebas/RowOrder/Scripts/gitversion.py", line 9, in <module>
from Foundation import NSMutableDictionary
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/Foundation/__init__.py", line 8, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/objc/__init__.py", line 26, in <module>
from _bridgesupport import *
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/objc/_bridgesupport.py", line 9, in <module>
import pkg_resources
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 651, in <module>
class Environment(object):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 654, in Environment
def __init__(self, search_path=None, platform=get_supported_platform(), python=PY_MAJOR):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 55, in get_supported_platform
plat = get_build_platform(); m = macosVersionString.match(plat)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 181, in get_build_platform
plat = get_platform()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/util.py", line 97, in get_platform
cfgvars = get_config_vars()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 525, in get_config_vars
func()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 408, in _init_posix
raise DistutilsPlatformError(my_msg)
distutils.errors.DistutilsPlatformError: $MACOSX_DEPLOYMENT_TARGET mismatch: now "10.5" but "10.6" during configure
Finished running custom build phase script: gitversion.py (exit status = 1)
Clearly, distutils has somehow hardcoded that it is compiled for version 10.6 (Snow Leopard, that is the one I am using), but the project has the MacOSX Deployment target set to 10.5.
If i try to set this variable in the project to 10.6, I then get:
ld: library not found for -lcrt1.10.6.o
Any ideas on how to solve this issue? Thanks in advance.

I have the same problem, and I wanted to keep the python version because handling the plist via NSMutableDictionary is much nicer than using regex on Info.plist.
Building on Maxence's answer, the solution was to strip the python code out of the Run Script build phase into a gitversion.py file:
#!/usr/bin/env python
import os
from Foundation import NSMutableDictionary
from subprocess import Popen, PIPE
p = Popen(
"/sw/bin/git rev-parse --short HEAD",
stdout=PIPE,
close_fds=True,
shell=True)
version = p.stdout.read()
print version
info = os.environ['INFOPLIST_FILE']
print info
plist = NSMutableDictionary.dictionaryWithContentsOfFile_(info)
print plist
plist['revision'] = version[:-1]
plist.writeToFile_atomically_(info, 1)
Then replace the original Run Script with a shell script:
env MACOSX_DEPLOYMENT_TARGET=10.6 python gitversion.py
Be sure to remember to change the Shell setting to /bin/sh.

Apple distributes Python 2.5 and 2.6 with Snow Leopard (10.6) and both are built with a deployment target of 10.6. If you really do need to target your application for 10.5, you can't safely use the Apple-supplied Pythons on 10.6 to deploy on 10.5.
The easiest solution may be to download and install a Python 2.6 from python.org. That Python is targeted for 10.3+, so it will work on both 10.5 and 10.6. You'll probably also need to ensure that that Python is installed on all machines where your app will be deployed.
Another option might be to create a separate stand-alone helper app using py2app with the python.org 2.6 and deploy that along with your main app. Or create your whole app under py2app. In either case, the app would contain its own python framework interpreter and framework, independent of the system version.
EDIT: Based on your comment, I'm not sure I understand your problem. Since you are running on 10.6, it's not clear to me (1) why you have the deployment target set to 10.5 and (2) if you need to have the deployment set to 10.5. I'm going to guess that you had an existing Xcode project that was developed on 10.5 and then imported or upgraded from Xcode on 10.5 to Xcode on 10.6. If that is the case, then I think the only thing that should have been needed to be done is to change the Active SDK from 10.5 to 10.6 (in the overview) in the top of the project window. Doing just that and forcing a Clean All Targets should solve the crt library not found error; if not, there is something wrong with the project dependencies.
On the other hand, if you really do need to develop on 10.6 for 10.5, then it seems that your gitversion.py is introducing an inadvertent dependency on python 2.6 (as can be seen by the traceback), which is not part of 10.5. Unless you really need python 2.6 features, you should be able to eliminate that by using python 2.5 which Apple provides on both 10.5 and 10.6. In that case, perhaps all you need to do is to ensure that you invoke python in the build phase script with /usr/bin/python2.5 rather than just python.

For the purposes of this script, you can simply temporarily set the value of MACOSX_DEPLOYMENT_TARGET to 10.6. So your command would be:
env MACOSX_DEPLOYMENT_TARGET=10.6 gitversion.py

Here you can find ths SOLUTION:
http://marcocattai.posterous.com/xcode-project-version-number-using-gitsvn

Related

PyCUDA -- problems importing pycuda.driver

Windows 10
Python 3.8
CUDA 11.5
I've installed what I believe to be a matching pycuda from this file:
pycuda-2021.1+cuda115-cp38-cp38-win_amd64.whl
This simple example fails
import pycuda.driver as drv
drv.init()
print("Detected {} CUDA devices".format(drv.Device.count()))
With this error:
Traceback (most recent call last):
File "C:/University of Arizona/weeds/tests/cuda-summary.py", line 5, in <module>
import pycuda.driver as drv
File "C:\Users\evan\AppData\Local\Programs\Python\Python38\lib\site-packages\pycuda\driver.py", line 65, in <module>
from pycuda._driver import * # noqa
ImportError: DLL load failed while importing _driver: The specified procedure could not be found.
NVCC is in my path
Adding os.add_dll_directory(os.path.join(os.environ['CUDA_PATH'], 'bin')) has no effect
The script works just fine on my Jetson Nano
Any ideas on how to get past this? I've searched and tried several solutions.
It is quite strange, but updating the Nvidia display driver fixed the issue for me.
But in my case there was no issue on my PC with the same versions of Windows, Python, CUDA and PyCuda. The issue appeared on the different Windows 10 machine, when launching the exe, packaged by PyInstaller. So, updating the display driver was the fix for this machine.

Can not import TensorFlow for Swift in Xcode Playground

I'm trying to use Swift for TensorFlow and have followed the directions found here: https://github.com/tensorflow/swift/blob/master/Installation.md
When I go ahead and import TensorFlow as such within a Swift Playground file:
import TensorFlow
I get this error: "The active toolchain is not compatible with playgrounds. libswiftCore.dylib could not be loaded"
I was able to use Swift for TensorFlow within the REPL so I know it should work. Anyone have any ideas as to how to fix this issue? It clearly works as shown in this demonstration: https://www.youtube.com/watch?time_continue=819&v=Yze693W4MaU
Get the latest stable toolchain (e.g. v 0.6), install it, then go to Xcode > File > New > Project > Macos - Command Line Tools (instead of Playground). Additionally, the December 23, 2019 development toolchain—and beyond—should not require switching to the Legacy Build System. More information in this discussion here.
Was running into this as well. Answered in the Google Group - turns out you need to make sure you are creating a macOS playground and not an iOS playground.
I had the same issue and it turns out is the playground type.
From the Google Group reply:
As a synthesis of answers above and my own experience now with the latest May 8, 2020 builds and comments from the Google Group, I find:
SUCCESS
Xcode Project Command-line (as #8bitmp3 answered above)
Command-line swiftc (using the -O argument. Note this is the compiler)
FAILURE
Xcode Playground macOS (as #ian-do originally asked)
Command-line swift (and confirmed by Google Group. Note this is the interpreter)
For those interested in the command-line success (macOS 10.15.4), install the toolchain from here, create the source code file inference.swift per this page, and execute the following:
# Test this command. Expected outcome is your existing Xcode app as show below
$ xcrun -f swift
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
# Switch to the new TensorFlow toolchain you installed
# Mine was located at /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.9.xctoolchain/
# Open the Info.plist file, locate CFBundleIdentifier, and copy the string value
# Mine was com.google.swift.20200507
$ export TOOLCHAINS=com.google.swift.20200507
# Test the switch to your TensorFlow toolchain. Note the different result
$ xcrun -f swift
/Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.9.xctoolchain/usr/bin/swift
# Compile your Swift for TensorFlow source code
$ cd <directory with .swift file>
$ swiftc -O -sdk `xcrun --show-sdk-path` inference.swift
# Run the program
$ ./inference
[[0.68070436]]

pySerial installed, but still getting ImportError

I am new to Python, so I have likely done something obviously wrong, though despite my best efforts I cannot figure out what.
I am running windows 7 64bit.
I only have Python 3.5 (32 bit) installed.
I updated pip to the latest version succesfully and used it to install pySerial. I am working in eclipse oxygen with PyDev installed. My run configuration does show the appropriate path (as far as I can tell):
run configuration in eclipse/PyDev
I have confirmed pySerial is installed by doing the following in python interpreter:
>>>help()
>>>modules
serial shows up in the list of modules.
also:
>>> import serial; print(serial.__file__)
C:\Python35\lib\site-packages\serial\__init__.py
Additionally, trying to use serial in the terminal works fine, as below:
>>> import serial
>>> s=serial.Serial("COM4")
>>> s
Serial<id=0x383b750, open=True>(port='COM4', baudrate=9600, bytesize=8, parity='N', stop
bits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)
However, when I try to run the following code as a file:
import serial
print ("Test Script")
I get the following error:
Traceback (most recent call last):
File "C:\Users\H260643\Desktop\Projects\EclipseWorkspace\CMP_Thous_Hr\Base.py", line 1, in <module>
import serial
ImportError: No module named 'serial'
For what it's worth, the eclispe editor window has also flagged that line saying it is an "unresolved import: serial"
Right after posting this I realized that the install path for python/pySerial did not match what was in my eclispe/PyDev run configuration. I corrected my run configuration and all is well.

Plone upgrade 3.3.5 to Plone 4.1.2

I am trying to upgrade a Plone site from 3.3.5 to Plone 4.1.2. I installed a clean copy of 4.1.2 and tried to copy the Data.fs to 4.1.2. I had to delete my members folder as it was of the type LargePloneFolder which is not supported anymore. On a 32 bit virtual machine, this worked just fine. However, I ran into errors on my 64bit virtual machine. Copying the Data.fs from Plone 3.3.5 (same machine) or the Data.fs from Plone 4.1.2 on the 32 bit machine resulted in the same error.
Stack Trace:
Iz#bigBox# bin/zeoserver fg
/usr/local/Plone/zeocluster/parts/zeoserver/bin/runzeo
Traceback (most recent call last):
File "/usr/local/Plone/buildout-cache/eggs/ZODB3-3.10.3-py2.6-linux-x86_64.egg/ZEO/runzeo.py", line 405, in <module>
main()
File "/usr/local/Plone/buildout-cache/eggs/ZODB3-3.10.3-py2.6-linux-x86_64.egg/ZEO/runzeo.py", line 402, in main
s.main()
File "/usr/local/Plone/buildout-cache/eggs/ZODB3-3.10.3-py2.6-linux-x86_64.egg/ZEO/runzeo.py", line 158, in main
self.open_storages()
File "/usr/local/Plone/buildout-cache/eggs/ZODB3-3.10.3-py2.6-linux-x86_64.egg/ZEO/runzeo.py", line 207, in open_storages
self.storages[opener.name] = opener.open()
File "/usr/local/Plone/buildout-cache/eggs/ZODB3-3.10.3-py2.6-linux-x86_64.egg/ZODB/config.py", line 177, in open
return FileStorage(config.path, **options)
File "/usr/local/Plone/buildout-cache/eggs/ZODB3-3.10.3-py2.6-linux-x86_64.egg/ZODB/FileStorage/FileStorage.py", line 185, in __init__
read_only=read_only,
File "/usr/local/Plone/buildout-cache/eggs/ZODB3-3.10.3-py2.6-linux-x86_64.egg/ZODB/FileStorage/FileStorage.py", line 1554, in read_index
h = fmt._read_data_header(pos)
File "/usr/local/Plone/buildout-cache/eggs/ZODB3-3.10.3-py2.6-linux-x86_64.egg/ZODB/FileStorage/format.py", line 150, in _read_data_header
h = DataHeaderFromString(s)
File "/usr/local/Plone/buildout-cache/eggs/ZODB3-3.10.3-py2.6-linux-x86_64.egg/ZODB/FileStorage/format.py", line 236, in DataHeaderFromString
return DataHeader(*struct.unpack(DATA_HDR, s))
File "/usr/local/Plone/buildout-cache/eggs/ZODB3-3.10.3-py2.6-linux-x86_64.egg/ZODB/FileStorage/format.py", line 246, in __init__
"Non-zero version length. Versions aren't supported.")
ValueError: Non-zero version length. Versions aren't supported.
Python Version: 2.6 shipped with Plone 4.1.2 Unified Installer
I tried to pack the db as well. using fsrecover.py on Plone 3.3.5 and using the graphics interface as well. But that does not help either. This is strange because I get absolutely no errors on my 32 bit installation and migration of Data.fs worked just fine.
I copy the db with the cp command preserving all the permissions with -p option which works fine on the 32 bit VM.
Pack your database and/or try to remove any old "ZODB Versions" in the Zope2 /Control_Panel inside your running Plone 3.3.x install before attempting a migration. Or try doing a ZEXP export of your entire Plone site and import it into a clean 3.3.5 install before attempting to do a 4.x migration. "Versions" (long-running transactions) are not supported in newer versions of ZODB and have been deprecated for at least a few years now.
See this thread:
https://mail.zope.org/pipermail/zodb-dev/2010-September/013620.html

Python Hello World in PyObjC on iPhone?

I installed the iphone-python package from Cydia, but the HelloPython app closes immediately when I run it from Springboard.
This may be a red herring, but I found the .py file in Terminal and tried to run it with python and got a python error:
$ python /private/var/stash/Applications.pwn/HelloPython.app/HelloPython.py
Traceback (most recent call last):
File "/private/var/stash/Applications.pwn/HelloPython.app/HelloPython.py", line 9, in <module>
import objc
File "/usr/lib/python2.5/objc/__init__.py", line 17, in <module>
_update()
File "/usr/lib/python2.5/objc/__init__.py", line 14, in _update
import _objc
ImportError: dlopen(/usr/lib/python2.5/lib-dynload/_objc.dylib, 2): Symbol not found: _OBJC_CLASS_$_Object
Referenced from: /usr/lib/python2.5/lib-dynload/_objc.dylib
Expected in: /usr/lib/libobjc.A.dylib
I'm running 4.3.3.
How can I get this app working, so I'll have a working example of PyObjC?
Well due to the changes in the way executables on the new ios run, the dynamic library has become corrupt. The mach-o will no longer run due to the upgraded objective-c so a workaround would be to compile pyobjc from source and run normaly. The only ptoblem with that is that the iphone's version of pyobjc is built for uikit so you would need to find saurik's (Jay Freeman) source code and compile it. I might do that for myself so ill post back with a deb file if i do.