Newbie problems getting started with Python API

First, yes, I've looked at the FAQ, but did not find anything relevant.
Second, I'm an experienced software engineer with 40 years experience of Lisp-like languages, but I don't know Python; the answer to this question is probably exceedingly obvious, but I can't see it.
Background: I'm working on a game which will have hundreds of thousands of non-player characters. That means, obviously, that storing all the models will be problematic and that I would rather generate them programmatically; but also, I want characters who are represented as being related to one another to look systematically similar. Consequently I'm experimenting with a system of simulated genetics such that I'm using a bit vector to represent the 'genome' of a character, and bitwise operations on the 'genome' of a 'mother' and a 'father' character to produce genomes for child characters. I then want to use information from the bit vector to manipulate a character model. I'm hoping to be able to use MakeHuman (or more precisely MHAPI to do this part, at least for proof-of-concept.
What I'm doing: First, I'm working in Clojure, which probably makes things more complicated! But second, I'm failing at the 'from core import G' step.
The code I'm sending to Python is
At which point it fails with
This issue relates. So the problem is that 'G' will only be valid in the same Python virtual machine as a current instance of the MakeHuman app is running.
So I hypothesised that if I started the MakeHuman app in my own Python session, I would be able to access 'G', but this too fails in the same way.
As I say, this is still failing with the 'AttributeError: 'NoneType' object has no attribute 'mhapi'' error.
Am I simply barking up the wrong tree, or is there a way to make this work?
Second, I'm an experienced software engineer with 40 years experience of Lisp-like languages, but I don't know Python; the answer to this question is probably exceedingly obvious, but I can't see it.
Background: I'm working on a game which will have hundreds of thousands of non-player characters. That means, obviously, that storing all the models will be problematic and that I would rather generate them programmatically; but also, I want characters who are represented as being related to one another to look systematically similar. Consequently I'm experimenting with a system of simulated genetics such that I'm using a bit vector to represent the 'genome' of a character, and bitwise operations on the 'genome' of a 'mother' and a 'father' character to produce genomes for child characters. I then want to use information from the bit vector to manipulate a character model. I'm hoping to be able to use MakeHuman (or more precisely MHAPI to do this part, at least for proof-of-concept.
What I'm doing: First, I'm working in Clojure, which probably makes things more complicated! But second, I'm failing at the 'from core import G' step.
The code I'm sending to Python is
- Code: Select all
import sys
sys.path.append('/home/simon/bin/mh/makehuman')
from lib.core import G
G.app.mhapi.internals.getHuman()
At which point it fails with
- Code: Select all
Execution error at libpython-clj2.python.ffi/check-error-throw (ffi.clj:707).
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'mhapi'
This issue relates. So the problem is that 'G' will only be valid in the same Python virtual machine as a current instance of the MakeHuman app is running.
So I hypothesised that if I started the MakeHuman app in my own Python session, I would be able to access 'G', but this too fails in the same way.
- Code: Select all
(ns cc.journeyman.simulated-genetics.makehuman-bridge
(:require [libpython-clj2.require :refer [require-python]]
[libpython-clj2.python
:refer [as-python as-jvm
->python ->jvm
get-attr call-attr call-attr-kw
get-item initialize!
run-simple-string
add-module module-dict
import-module
py. py.. py.-
python-type
;; dir
]
:as py]
[taoensso.telemere :refer [error! trace!]]))
(defn initialise-makehuman!
"Initialise the local instance of MakeHuman. `mh-path` should be a valid
path to the directory in which MakeHuman is installed, i.e. the directory
which contains `makehuman.py`."
[^String mh-path]
(initialize!)
(map #(trace! (run-simple-string %))
["import sys"
(format "sys.path.append('%s')" mh-path)
(format "exec(open('%s/makehuman.py').read())" mh-path)
"from lib.core import G"
"G.app.mhapi.internals.getHuman()"
]))
As I say, this is still failing with the 'AttributeError: 'NoneType' object has no attribute 'mhapi'' error.
Am I simply barking up the wrong tree, or is there a way to make this work?