To use Python normally from software created with openFrameworks, chaosct's ofxPython or satoruhiga's ofxPy It's easy to use (/ satoruhiga / ofxPy), but I wanted to use Python in the Anaconda package installed using pyenv on OSX, so I tried it.
Here, oF 0.9.8 is used on OSX using ofxPy. Introducing Python 3.6.1 that comes with Anaconda 3-4.3.1.
In my case, I usually made an app with project-generator. Of course ofxPy has been added.
Open the project and first populate the Python library.
Since the installation directory is /Users/me/.pyenv/versions/anaconda3-4.3.1
, drag and drop" libpython3.6m.dylib "in the lib directory in it. At this time, you will be asked if you want to copy the library file to the project directory as an option, but you do not have to copy it.
Next, edit the build settings for your project.
Add the following to Header Search Paths
. Replace the directory with the anaconda installation directory that is being used as appropriate.
/Users/me/.pyenv/versions/anaconda3-4.3.1/include
/Users/me/.pyenv/versions/anaconda3-4.3.1/include/python3.6m
Then, Library Search Paths
/Users/me/.pyenv/versions/anaconda3-4.3.1/lib
In addition, set a similar path in Runpath Search Paths to prevent you from being told "no libraries" at runtime.
/Users/me/.pyenv/versions/anaconda3-4.3.1/lib
In the project build phases, add "libpython3.6m.dylib" to Copy Files. In my case, I just added it and did not set the Destination or Subpath.
Basically, the ofxPy's example file should work, but if you just check the operation, it will be successful if there is no error in the following code.
The important thing is that you may not be able to use Python with the message "Set $ PYTHONHOME
, so use the ** putenv
function to set the environment variable in the program to the path to the Python home (= Anaconda directory). Is to be specified **.
ofApp.h
#pragma once
#include "ofMain.h"
#include "ofxPy.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
ofxPy::Context python;
};
ofApp.cpp
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofSetFrameRate(0);
ofSetVerticalSync(false);
ofBackground(0);
putenv((char *)"PYTHONHOME=/Users/me/.pyenv/versions/anaconda3-4.3.1");
python.setup();
}
You should be able to use it.
Recommended Posts