I created a dll file using Visual Studio 2010 for python script which contains only python function and used it in labview using "Call Library Function Node" VI available in labview. It works fine.
Followed the same procedure in the link below
"http://www.originlab.com/doc/OriginC/guide/Access-Python-via-External-DLL"
But if I am creating a dll file for python script containing opencv and python functions labview throws memory issue.
Do I need to add some other dependencies of OpenCV as well. If so, then what should be added?
Related
I'm using a library which offers a python wrapper to a c++ executable.
I installed it (https://github.com/bulletphysics/bullet3) using venv (https://docs.python.org/3/library/venv.html) - and all is working great.
I'm considering trying to build https://github.com/bulletphysics/bullet3
From the root of the venv folder I found gym/lib/python3.7/site-packages/pybullet.cpython-37m-x86_64-linux-gnu.so. I'm guessing this is the executable that is invoked eventually from python.
What steps are involved in calling from Python to the correct external binary executable? How does import pybullet as p resolve to gym/lib/python3.7/site-packages/pybullet.cpython-37m-x86_64-linux-gnu.so?
This seems to be close to the end of the c++ world; but I can't find the right key word searches to see exactly how that allows python usages.
Thanks
In short words: C-python just looks for correctly named dynamic libraries in PYTHONPATH, loads such library and uses predefined interface to understand what exactly from this library shall be visible as contents of the module inside Python.
In long words details of how to prepare such shared object and what are required contents of it are described in https://docs.python.org/3/extending/index.html
So venv just puts dynamic library in directory which is part of PYTHONPATH of virtual environment.
python just looks for correctly named dynamic libraries in PYTHONPATH, loads such library and uses predefined interface
for further info :
https://docs.python.org/3/extending/index.html
I am making a game engine in cpp and I want to add python scripting support. I want the python script to be able to access classes from my cpp API and cpp to be able to call functions on the script for example Update(Delta time) every frame. Im using Visual Studio 2017. The cpp should be the host of the python code.
How should I interface with a python VM in my cpp VS2017 project ?
How should I give the script access to cpp classes ?
To clarify:
This is not a debugging question it's a design question.
It's important to me to have full control of the python environment.
This is not a python project extended with CPP performance code.
It should be a native unmanaged cpp project extended with python scripting support.
I'm new at Python, and I'm trying to write my first Python application on Visual Studio CE 2015 using IronPython.
I finally managed to execute the most basic .NET-compatible code importing the clr module (which comes with the whole IronPython package) but, since my goal is writing an application that reads from a USB scale following this blog post, I'm stuck at trying to import the usb module.
I downloaded and installed both pyUSB and libusb, so I thought I had to simply add the reference in the "reference" section like any other normal .NET applications, but I can't find nor the reference nor the DLL file path. What's the missing link??
import clr
clr.AddReferenceToFileAndPath(r"What\Is\The\Path\Going\Here?")
import usb.core
Thanks to #Xaerxess, I finally understand python libraries are just .py files that are to be found in the compiler directory. I copied the usb directory under the compiler's lib directory and it worked.
Background
I'm working with Python 2.7.6 and Matlab 2016a and have installed the official MathWorks Python to Matlab bridge. It is the matlab and matlab.engine modules. All of the other questions I've seen on SO regarding matlab/python use third-party wrappers that seem out of date. I have no experience programming in matlab itself, but plenty of python experience.
I'm currently porting this wrapper code from matlab_wrapper to the matlab module: https://github.com/javiergonzalezh/dpp. matlab_wrapper did not work for me (gave an undefined symbol in the openssl library that installed with matlab 2016a), hence the port to something that does work and will be maintained for future versions of matlab.
Question
This documentation shows how to call user defined functions (.m files) that are in the current directory.
http://www.mathworks.com/help/matlab/matlab_external/call-user-script-and-function-from-python.html
How can I call matlab user functions from any cwd using the matlab module in python? Is there some kind of OS environment $PATH variable or some matlab equivilent? If it helps, the .m files reside in the same directory as the calling python code.
Due to the comment by #excaza, I solved this by setting the MATLABPATH environment variable to point to the folder containing my *.m files.
http://www.mathworks.com/help/matlab/matlab_env/add-folders-to-search-path-upon-startup-on-unix-or-macintosh.html
I have an application written in python 2.7 . In my app I want to give users the ability to compile a python source file (i.e py to pyc).
The builtin compile function does this but the output file is only compatible with python 2.7.
What I want is to compile the file to a range of different python versions (specifically python 2.5 , 2.6 & 2.7 )
I know that one way to approach this problem is re-write my application in each of those versions and just use the inbuilt compile function, but I do not want to do this.
I am open to all suggestions including writing a C extension, embedding python etc...
EDIT
The application which I am writing is a tool which allows to inject/modify arbitrary code inside a pyinstaller exe.
Now you may be knowing that pyinstaller actually puts compiled python source files within the exe.
My app just extracts these embedded pyc files, decompiles them, allows the user to modify them, and then rebuild the exe.
Since the exe can be from a different python version, so I need the functionality to compile the decompiled output to that version.
Here is a screenshot of that app.
I solved my own problem in a different approach.
Now, my main app is written in python 2.7. I wrote 2 dll each of which had a python interpreter embedded. Within one I embedded python 2.6 and within other python 2.5.
Each of these two dlls uses the Python C API to compile a script given as an argument to the respective python version.
Now, from my main app (written in python 2.7) , I used ctypes to call the exported functions from these two dlls. The script to compile was passed as an argument.
Using this approach I was able to compile a given script to any of the 3 python versions.