Comments (8)
No problem, this is what I got from your explanations.
from ocaml_python_bindgen.
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.
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.
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.
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.
(But yes embedding the python file in the executable somehow would be very cool....)
from ocaml_python_bindgen.
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.
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)
- supporting python functions returning tuples would be _very_ useful HOT 9
- embedding more than one python file HOT 5
- Generated OCaml interface's style HOT 6
- You don't always need to generate the pyobject conversions functions
- --embed-python-source HOT 29
- "could not create val_spec" is not very helpful HOT 3
- t option and custom option arguments are tricky to handle correctly HOT 1
- pyml_bindgen invocation example in case there is no class [question] HOT 4
- there are many depends in the opam file HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ocaml_python_bindgen.