> - I had to set path to both "lib" and to "lib/lib-dynload" - why is that?
> If I remember correctly, on Windows there used to be two directories "Lib"
> and "libs" (?) - one containing C extensions and the other one pure Python
> modules. That has changed? In any case, why do I have to point to the
> "lib-dynload" as well, why can't the interpreter recursively search the top
> most "lib"? And if I wanted to include new modules, should I put them
> inside "site-packages"?
I don't have an answer for that.
> - the docs say, "The path components should be separated by semicolons"
> that is ";" - but I had to use ":" - I'm on Mac, maybe the are the docs
> Windows specific?
Then I think the doc is wrong. I do the following:
#ifdef _WIN32
char separator = ';';
#else
char separator = ':';
#endif
> - to enable Python to import stdlib, is it the right way to do so with
> "Py_SetPath()"?
> Or are there other idioms?
It is the right way.
> - I read somewhere sometime that it may be possible to incude giant .zip
> file, instead of all the libraries files (.py, .so) - is it true? How does
> a script import from such an archive?
The Python interpreter can read zip files.
This is what I do myself. I zip the entire Python library and embed it
inside my application. Then I extract it at run-time in a temporary
directory, then I point the Python interpreter to it using Py_SetPath.
> I hope you don't mind such newbie questions...
Not at all.
Extending and embedding and distributing Python within an application
seems to be the most common use case. Once you know what to do, it is
actually very simple. But it is not covered in the documentation, nor
are there any examples. I only succeeded because I actually read the
CPython source code.
Maybe, some day, somebody will feel generous and publish an example of
how to do that. Until then, this is the best place to ask questions.
--
Francis Bolduc, B.Sc.
CM-Labs Simulation Inc.
Hello,
I managed to embed Python interpreter and now I would like to include all
of the standard library with the app.
I built Python from source and it created a folder "lib/python3.3" with all
the libraries, it seems. Before I do "Py_Initialize()" I had to do
"Py_SetPath()"
pointing to the application directory (there I copied the whole "lib"). It
works but I have a few questions. Please:
- I had to set path to both "lib" and to "lib/lib-dynload" - why is that?
If I remember correctly, on Windows there used to be two directories "Lib"
and "libs" (?) - one containing C extensions and the other one pure Python
modules. That has changed? In any case, why do I have to point to the
"lib-dynload" as well, why can't the interpreter recursively search the top
most "lib"? And if I wanted to include new modules, should I put them
inside "site-packages"?
- the docs say, "The path components should be separated by semicolons"
that is ";" - but I had to use ":" - I'm on Mac, maybe the are the docs
Windows specific?
- to enable Python to import stdlib, is it the right way to do so with
"Py_SetPath()"?
Or are there other idioms?
- I read somewhere sometime that it may be possible to incude giant .zip
file, instead of all the libraries files (.py, .so) - is it true? How does
a script import from such an archive?
I hope you don't mind such newbie questions...
I think there is a macro defined in one the Qt headers that turns
"slots" into nothing.
This allows the following to work:
#include <QWidget>
class Something : public QWidget
{
Q_OBJECT
public slots:
void doStuff();
};
That would explain why you get this error message. You compiler sees:
PyType_Slot *;
Because the "slots" word disappeared.
At least that's my theory.
Can you include Python.h before including any Qt headers, maybe
that'll solve your problem.
On Mon, Feb 25, 2013 at 12:22 PM, ecir hana <ecir.hana(a)gmail.com> wrote:
> Hello,
>
> I try to embed Python into Qt application but when I add
>
> #include <Python.h>
>
> at the top for working app, the compilation breaks with:
>
> ../sample/python3.3m/object.h:432:23: error: expected member name or
> ';' after declaration specifiers
> PyType_Slot *slots; /* terminated by slot==0. */
> ~~~~~~~~~~~ ^
>
> Please, does anyone know why this happens? I'm new to all this compilation
> stuff - could it be that Python defines the same names as Qt? Namely
> "slots"?
>
> Qt uses "clang++", it that changes anything...
> _______________________________________________
> capi-sig mailing list
> capi-sig(a)python.org
> http://mail.python.org/mailman/listinfo/capi-sig
--
Francis Bolduc, B.Sc.
CM-Labs Simulation Inc.
Hello,
I try to embed Python into Qt application but when I add
#include <Python.h>
at the top for working app, the compilation breaks with:
../sample/python3.3m/object.h:432:23: error: expected member name or
';' after declaration specifiers
PyType_Slot *slots; /* terminated by slot==0. */
~~~~~~~~~~~ ^
Please, does anyone know why this happens? I'm new to all this compilation
stuff - could it be that Python defines the same names as Qt? Namely
"slots"?
Qt uses "clang++", it that changes anything...
Ecir,
please don't post such dumps to the mailing list. Use
some pastebin service instead.
The dump doesn't show the locations gcc is looking
at (except for your current dir), so it doesn't really
help.
I'd suggest you get some help from a gcc/Mac OS X related
forum to sort out the linking problem, as it is not Python
specific.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Feb 24 2013)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
On 24.02.2013 15:48, ecir hana wrote:
> On Sun, Feb 24, 2013 at 3:43 PM, M.-A. Lemburg <mal(a)egenix.com> wrote:
>
>> On 24.02.2013 15:18, ecir hana wrote:
>>
>
>> Try a dtruss of the operation to check what gcc is looking for
>> and where.
>>
>
> You mean "sudo dtruss gcc -lname python33"? Do you mind if I post the
> result here, as I don't really understand what it is doing?
You need to run "sudo dtruss -f gcc -lpython3.3", since the trace
you posted stops at the vfork() and doesn't include the interesting
parts.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Feb 24 2013)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
On 24.02.2013 15:18, ecir hana wrote:
> On Sun, Feb 24, 2013 at 3:10 PM, M.-A. Lemburg <mal(a)egenix.com> wrote:
>
> You can try to use dylibs
>> for your application, but chances are high that your users will
>> run into problems picking up a dylib from one of the many sources
>> for this file
>>
>
> I thought that if I include the dynamic library into the application bundle
> it should pick the version I provide..?
That's how it works on Windows, but not on a typical Unix system.
I don't know how Mac OS X works if you put the dylib into the
application bundle - AFAIK, the bundle is just a directory, i.e.
not special when it comes to linking, but I could be wrong.
>> "gcc -lname" will look for a file libname.a or libname.dylib. Please
>> see the man page for details.
>>
>
> That's exactly the problem, The folder has "libpython33.dylib" file but
> when I do "gcc -lname libpython33" it says
> "i686-apple-darwin11-llvm-gcc-4.2: libpython33: No such file or directory".
Try a dtruss of the operation to check what gcc is looking for
and where.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Feb 24 2013)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
On 24.02.2013 14:55, ecir hana wrote:
> On Sun, Feb 24, 2013 at 2:30 PM, M.-A. Lemburg <mal(a)egenix.com> wrote:
>
>>
>> Something is wrong here: the library is usually called something
>> like "libpython3.3m.a".
>>
>
> There was "libpython3.3.dylib" which is a symlink to "Python" which I
> renamed to "python33" so it does not collide with installed "Python" v2.7.
> I also tried "python33.dylib", "libpython33", "libpython33.dylib",
> "libpython33.so" to no avail...
Sorry, I can't help with the versions from the Python installer
on python.org. Both the Apple provided and the python.org versions
have given us too much trouble in the past. We're always compiling
our own versions, try to avoid fat binaries and use default settings
when compiling Python.
> Btw, why ".a"? I thought that for static linking. The binary distribution
> from python.org only contains some dylibs...
The .a libs are indeed for static linking. You can try to use dylibs
for your application, but chances are high that your users will
run into problems picking up a dylib from one of the many sources
for this file (Apple's Python lib, python.org installer, MacPorts,
Homebrew, Fink, etc.). Each of those will likely have been compiled
using slightly different settings or even come with internal changes.
You can avoid all that by doing static linking.
> Please make sure that you actually have the correct library in
>> your current directory.
>>
>
> I think I have - it just those 3 files from above in the directory.
"gcc -lname" will look for a file libname.a or libname.dylib. Please
see the man page for details.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Feb 24 2013)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
On 24.02.2013 13:25, ecir hana wrote:
> Hello,
>
> I would like to embed Python 3.3, I followed the simplest tutorial here:
> http://docs.python.org/3.3/extending/embedding.html
>
> I'm on MacOS 10.8 which has Python 2.7 but I would like to embed the 3.3
> version. I downloaded v3.3 binary distribution from python.org for Mac. I
> unzipped the archive, took out all the headers and "Python" dynamic library
> to a new folder. I then renamed the "Python" file to "python33" so that it
> wont collide with installed Python 2.7. So in the folder, there are:
>
> embed.c
> include (folder)
> python33
>
> Running "file python33" says:
>
> python33 (for architecture i386): Mach-O dynamically linked shared
> library i386
> python33 (for architecture x86_64): Mach-O 64-bit dynamically linked
> shared library x86_64
Something is wrong here: the library is usually called something
like "libpython3.3m.a".
> and embed.c is:
>
> #include <Python.h>
>
> int
> main(int argc, char *argv[])
> {
> Py_Initialize();
> PyRun_SimpleString("print 'test'\n");
> Py_Finalize();
> return 0;
> }
>
> It compiles but when I do "gcc embed.c -I./include -L. -lpython33" it
> breaks with:
>
> ld: library not found for -lpython33
This would have to be -lpython3.3m or similar.
> Please, does anyone know how to make it compile? I don't want to *install*
> Python 3.3 - is it possible to just extract the dynamic library from the
> binary distribution and use it, like I did above? I also tried:
>
> DYLD_LIBRARY_PATH="." gcc embed.c -I./include -L. -lpython33
>
> but it doesn't work.
Please make sure that you actually have the correct library in
your current directory.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Feb 24 2013)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/