Use Anaconda-Python installed with pyenv from openFrameworks

I want to use pyenv's Python while using add-ons

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.

Creating and coordinating projects

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. pyenv-of-01.jpeg

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.

Test code

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

Use Anaconda-Python installed with pyenv from openFrameworks
Make OpenCV3 available from python3 installed with pyenv
Use Python installed with pyenv for PL / Python execution environment
Install the latest Python from pyenv installed with homebrew
Use python installed with Pyenv with Sublime REPL of Sublime Text 3
Use Python in pyenv with NeoVim
Use pydoc with Virtualenv / pyenv / venv
I couldn't use tkinter with python installed by pyenv of anyenv
Use smbus with python3 under pyenv environment
Use C ++ functions from python with pybind11
pyenv doesn't work with tcl-tk installed by homebrew.
Use multiple versions of python environment with pyenv
Wrap C with Cython for use from Python
Wrap C ++ with Cython for use from Python
PIL cannot be installed by virtualenv with pyenv
Create a virtual environment with Anaconda installed via Pyenv
Environment construction with anyenv + pyenv (migrate from pyenv only (Mac))
Use thingsspeak from python
Use mecab-ipadic-neologd with igo-python
Use RTX 3090 with PyTorch
Use ansible with cygwin
Use pipdeptree with virtualenv
[Python] Use JSON with Python
Use Mock with pytest
Use fluentd from python
Use indicator with pd.merge
Use Gentelella with django
Use mecab with Python3
Use tensorboard with Chainer
Use DynamoDB with Python
Use Python 3.8 with Anaconda
Use python with docker
Use TypeScript with django-compressor
Use MySQL from Python
Use LESS with Django
How to use Pyenv
Install python with pyenv
Use BigQuery from python.
Build python3.x with pyenv
Use MySQL with Django
Use Enums with SQLAlchemy
A memorandum (masOS) that import tkinter could not be done with python installed from pyenv
Use tensorboard with NNabla
Use GPS with Edison
Use nim with Jupyter
Use mecab-ipadic-neologd from python
Use ssh with private key public key authentication. Connect from wan.