GithubHelp home page GithubHelp logo

Comments (8)

UnixJunkie avatar UnixJunkie commented on June 23, 2024 1

No problem, this is what I got from your explanations.

from ocaml_python_bindgen.

mooreryan avatar mooreryan commented on June 23, 2024

Hey, this is a good question. I'm working on adding a couple of examples to the repo to show how to do this correctly. I will update you when they are ready!

from ocaml_python_bindgen.

mooreryan avatar mooreryan commented on June 23, 2024

The short answer is that you could set the PYTHONPATH environmental variable to wherever the python module you want to bind is located. Or you can "install" the python package in the typical python way.

The longer answer....So I added some examples that may help you out. This one in particular has some modules that it's importing (https://github.com/mooreryan/ocaml_python_bindgen/tree/main/examples/importing_modules). The readme in there is fairly detailed, so hopefully it will help. Oh and as a bonus, the dune files shows how to set up dune rules to automatically generate the bindings when your specs are updated.

If you need more help, let me know. Otherwise, feel free to close the issue!

from ocaml_python_bindgen.

UnixJunkie avatar UnixJunkie commented on June 23, 2024

Better answer, I asked to @thierry-martinez:
thierry-martinez/pyml#77
So, simple answer,

let toto = Py.Import.import_module "toto"

Now, combine this with mirage/ocaml-crunch, and we can have an ocaml library/executable
which can embeds the few python files it needs!
--> deployment heaven

from ocaml_python_bindgen.

mooreryan avatar mooreryan commented on June 23, 2024

I saw that issue on the pyml repository as well. Yes that is correct that you need to use Py.Import.import_module, and in fact, that is what pyml_bindgen is doing (see here for example).

However, it doesn't change the fact that you will need to let Python know how to actually find the module. The simplest way to do that is probably with the PYTHONPATH environment variable (or just installing the package). This readme has an example of this.

(Perhaps I'm misunderstanding your question...?)

from ocaml_python_bindgen.

mooreryan avatar mooreryan commented on June 23, 2024

(But yes embedding the python file in the executable somehow would be very cool....)

from ocaml_python_bindgen.

UnixJunkie avatar UnixJunkie commented on June 23, 2024

ok, PYTHONPATH would be the basic way, so if should let opam install the python file somewhere and then reflect
this in PYTHONPATH

from ocaml_python_bindgen.

mooreryan avatar mooreryan commented on June 23, 2024

Sorry for the confusion...let me try an explain it a different way in case others have the same question as well.

If you have a python package installed in the "normal" way...say pip install matplotlib or whatever, then the pyml/pyml_bindgen generated library (which uses Py.Import.import_module) will be able to find any of the matplotlib modules because it will be installed in a location in which python "looks" for modules.

If you want to use a python module not installed with pip, conda, or whatever (e.g., just in some folder in your projects directory for example) then the (probably) best way to let python know about that module is to add the directory to the PYTHONPATH.

from ocaml_python_bindgen.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.