Embedding specific Python - python-3.5

I am currently embedding Python3 into my C++ application.
We also ships a defined version of Python3. Currently Py_Initialize finds the system python in /usr/lib/python3.5 (which we do not want). I could not yet figure out how I can strip the search path before calling Py_Initialize and force it to search in my custom path.

It can be done with Py_SetPythonHome.

Related

How to compile .ui file to python using pyside6-uic but with the snake_case and true_property activated

The new version of Qt for Python (PySide6) allows to use a new feature named true_property, this feature you can easily use when you build your UI manually from scratch, but If you are using Qt Designer and you want to convert .ui files to python using pyside6-uic the python code is generated without taking in count that feature. So I want to know if there is a flag option or a command to tell pyside6-uic to use the true_property.

How to syntax check Python?

I'm writing just a simple Python 3 program (beginner here) and I want to syntax check the code rather than just run it and see errors. How can I do this?
I've done python3 -m py_compile sender.py but nothing changes or is displayed. I'm using version 3.5.2 in Ubuntu, and sender.py is in the directory that I'm currently in.
There are some Python editors than can do this.
For example, Spyder and PyCharm.
They highlight the code segments that have problems.
If you are looking for tools similar to regular compilers, then you can have a look at this stackoverflow question and this with good answers.

Is there a directory where i can put a d file so that the compiler automatically includes it?

I am new to the D programming language, and would like to use ncurses in D. I have found a good D port of ncurses, but I want to be able to import it in any source file without writing:
gdc <files> ncurses.d
Is there any way I can make it included every time?
Btw I am using gdc on debian Gnu/Linux.
No. You should consider using a build tool, such as rdmd, which will automatically construct a compiler's command line and add all modules included by your program.
If, for some reason, you don't want to use a build tool, a common approach is to use a Makefile.

is there a way to install the nodebox English linguistics library through pip install?

The NodeBox English linguistic library for Python has some nice features, like conjugation, that could be very useful for a project.
I tried installing through pip in a particular virtualenv, but pip search nodebox only brings up:
NodeBox - Simple application for creating 2-dimensional
graphics and animation using Python code
nodebox-color - Color classes for python
NodeBox-for-OpenGL - 2D animation with Python code
nodebox-opengl - NodeBox for OpenGL is a free, cross-platform
library for generating 2D animations with Python
programming code.
Is it pip-installable (in a virtualenv) by another name maybe? Or is the only way to install to
Put the en library folder in the same folder as your script so NodeBox
can find the library. You can also put it in ~/Library/Application
Support/NodeBox/. It takes some time to load all the data the first
time.
as stated on their website?
The Nodebox library has been succeeded by pattern, which is on the PyPI. The NLP functionality is contained in the pattern.en module. It can be installed with:
pip install pattern

Start application from Matlab

I'm looking for a way to start an application from within Matlab. The thing is, my Matlab script saves some results to a file, which should then be opened in the associated application (Blender in this case).
I'm familiar with commands like
system('program_name')
or
!program_name
and some other ways, but the thing is, the application is started with the Matlab PATH, so it looks inside the Matlab directory for all kinds of libraries it needs. For instance:
>> !blender
blender: /usr/local/MATLAB/R2011a/sys/os/glnx86/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by blender)
Is there some way to start an application, which uses the global (system) PATH?
A moment ago I thought I found a tweak, namely starting a terminal from within Matlab, with some arguments (Blender filename.blend).
system('terminal -x blender /home/pieter/Red.blend')
This did work a couple of times, but now I'm getting errors after executing this command 20 times or so...
>> system('terminal -x blender /home/pieter/Red.blend')
(terminal:10982): GLib-CRITICAL **: PCRE library is compiled without UTF8 support
(terminal:10982): Terminal-CRITICAL **: Failed to parse regular expression pattern 0: PCRE library is compiled without UTF8 support
I'm using Arch Linx, by the way.
Edit:
Well, I just thought of a rather dirty solution. Matlab uses the environment variable
LD_LIBRARY_PATH
For the paths to the necessary libraries:
getenv('LD_LIBRARY_PATH')
/usr/local/MATLAB/R2011a/sys/os/glnx86:/usr/local/MATLAB/R2011a/bin/glnx86:/usr/local/MATLAB/R2011a/extern/lib/glnx86:/usr/local/MATLAB/R2011a/runtime/glnx86:/usr/local/MATLAB/R2011a/sys/java/jre/glnx86/jre/lib/i386/native_threads:/usr/local/MATLAB/R2011a/sys/java/jre/glnx86/jre/lib/i386/client:/usr/local/MATLAB/R2011a/sys/java/jre/glnx86/jre/lib/i386
So I could save this information to a variable (e.g. MatlabPath):
MatlabPath = getenv('LD_LIBRARY_PATH')
and then before I call blender do this:
setenv('LD_LIBRARY_PATH',getenv('PATH'))
Which makes Matlab use my system libraries. Then after the program has started, re-assign the old value to LD_LIBRARY_PATH:
setenv('LD_LIBRARY_PATH',MatlabPath)
So... it is a solution, but if anybody knows a cleaner way of solving the problem, let me know.
As I indicated in my Edit above, this could be a solution:
% Save library paths
MatlabPath = getenv('LD_LIBRARY_PATH');
% Make Matlab use system libraries
setenv('LD_LIBRARY_PATH',getenv('PATH'))
disp('Starting Blender...')
system( ['blender ', Directory, FileName, '.blend'] )
% Reassign old library paths
setenv('LD_LIBRARY_PATH',MatlabPath)
However, with the other way to start an application, you can immediately return to Matlab after starting it:
% Start Blender and immediately return to Matlab
!blender Geometry.blend &
The ampersand (&) is the key to immediately return to Matlab after starting the application , but starting Blender this way I cannot provide a variable FileName like I can do with system(...).
So, anybody got a clue on how to
use !program_name with a variable filename
or
use system(program_name) with an option such that Matlab just starts the application (and doesn't wait with returning until the application has been closed)
Just run command in MATLAB:
setenv('LD_LIBRARY_PATH',[getenv('PATH') getenv('LD_LIBRARY_PATH')])
It appends matlab library in system library.
You can actually clear out the LD_LIBRARY_PATH variable in your system call, like this:
system('LD_LIBRARY_PATH=; blender');
(Note that this most likely depends on the command syntax of the shell that's launched internally by MATLAB. The above should work for Bash).

Resources