473,624 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Embedding, "import site", PYTHONHOME, and an old, old issue

Well, I've found about a hundred thousand web pages where people have
had the same problem I have but nary a page with a solution that works
for me.

I want to do a simple embed, so I've followed the example in the
Extending and Embedding documentation:

In the .c file,

#include <Python.h>

int routine() {
Py_Initialize() ;
PyRun_SimpleStr ing("from time import time,ctime\n"
"print 'Today is',ctime(time( ))\n");
Py_Finalize();
return 0;
}

The code compiles just fine, but when I execute it the call to
Py_Initialize() comes back with:

'import site' failed; use -v for traceback
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named time

I found a lot of websites that say to set PYTHONHOME to the the path to
the directory where site.py lives. I did that but I get the same error.

Here are a few bits o' additional information:

'python -v' tells me it was built with gcc 3.4.4 (and has no trouble at
all finding site.py whether PYTHONHOME is defined or not). The
following code snippet:
>>import distutils.sysco nfig
distutils.sys config.get_conf ig_var('LINKFOR SHARED')
comes back with '-Xlinker -export-dynamic'.

My own code needs to use Portland Group's pgi. I did some googling for
various permutations of nouns from the preceding few paragraphs and
found Pythonic mention of using "-Wl,-export-dynamic" as a flag for the
PG linker. OK, try that, builds fine, same error.

I cannot recompile Python on this machine and I don't really understand
exactly what is happening with the Py_* function calls in the C snippet
above, or whether I can get more detailed traceback info. This is the
first time I've tried embedding and it's rather obvious that I've run
into a problem that everyone but Messrs. van Rossum and Lundh has hit.
Somebody, somewhere must have an honest-to-glub solution. If you are
that somebody, please let me know what to do because I'm about to throw
in the towel and embed That Other Language.

Oh, one more thing: if I launch python from the shell and type in the
strings from the C snippet it works fine.

Thanks,
Jim
--

It's not "pretexting ", it's "lying."
Feb 10 '07 #1
3 6856
Jim Hill (that'd be me) wrote:

I forgot one more key thing: the compiled code is being run via mpirun
(LAM/MPI). Might that have something to do with my pain and heartache?
Jim

(original post reproduced below in shocking breach of etiquette on the
off chance someone's interested in this post and didn't bother reading
the first.)

>Well, I've found about a hundred thousand web pages where people have
had the same problem I have but nary a page with a solution that works
for me.

I want to do a simple embed, so I've followed the example in the
Extending and Embedding documentation:

In the .c file,

#include <Python.h>

int routine() {
Py_Initialize() ;
PyRun_SimpleStr ing("from time import time,ctime\n"
"print 'Today is',ctime(time( ))\n");
Py_Finalize();
return 0;
}

The code compiles just fine, but when I execute it the call to
Py_Initialize( ) comes back with:

'import site' failed; use -v for traceback
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named time

I found a lot of websites that say to set PYTHONHOME to the the path to
the directory where site.py lives. I did that but I get the same error.

Here are a few bits o' additional information:

'python -v' tells me it was built with gcc 3.4.4 (and has no trouble at
all finding site.py whether PYTHONHOME is defined or not). The
following code snippet:
>>import distutils.sysco nfig
>>distutils.sys config.get_conf ig_var('LINKFOR SHARED')

comes back with '-Xlinker -export-dynamic'.

My own code needs to use Portland Group's pgi. I did some googling for
various permutations of nouns from the preceding few paragraphs and
found Pythonic mention of using "-Wl,-export-dynamic" as a flag for the
PG linker. OK, try that, builds fine, same error.

I cannot recompile Python on this machine and I don't really understand
exactly what is happening with the Py_* function calls in the C snippet
above, or whether I can get more detailed traceback info. This is the
first time I've tried embedding and it's rather obvious that I've run
into a problem that everyone but Messrs. van Rossum and Lundh has hit.
Somebody, somewhere must have an honest-to-glub solution. If you are
that somebody, please let me know what to do because I'm about to throw
in the towel and embed That Other Language.

Oh, one more thing: if I launch python from the shell and type in the
strings from the C snippet it works fine.
--

It's not "pretexting ", it's "lying."
Feb 10 '07 #2
En Sat, 10 Feb 2007 03:57:05 -0300, Jim Hill <ji*****@swcp.c omescribió:
I want to do a simple embed, so I've followed the example in the
Extending and Embedding documentation:

In the .c file,

#include <Python.h>

int routine() {
Py_Initialize() ;
PyRun_SimpleStr ing("from time import time,ctime\n"
"print 'Today is',ctime(time( ))\n");
Py_Finalize();
return 0;
}
(Why routine() and not main()? Unfortunately you can't repeteadly
initialize/finalize the interpreter, you must do that only once.)
The code compiles just fine, but when I execute it the call to
Py_Initialize() comes back with:

'import site' failed; use -v for traceback
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named time
Try this:
PyRun_SimpleStr ing("import sys; print sys.path");
to see where Python expects to find its library (or call the Py_GetPath
function).

You may need to call Py_SetProgramNa me (before Py_Initialize) so it can
find where the standard library resides.
At least for testing purposes, you can copy your executable into the same
directory where Python is installed.

--
Gabriel Genellina

Feb 10 '07 #3
Gabriel Genellina wrote:
>En Sat, 10 Feb 2007 03:57:05 -0300, Jim Hill <ji*****@swcp.c omescribió:
>int routine() {
Py_Initialize() ;
...
}

(Why routine() and not main()? Unfortunately you can't repeteadly
initialize/finalize the interpreter, you must do that only once.)
This is a small routine tucked off to the side of a fairly large
mostly-FORTRAN-with-some-C program. I need to parse a slash-delimited
input file from a different program and fill up some arrays with the
results. Rather than wrestle with FORTRAN's wretched file I/O I thought
I'd do it this way.
>Try this:
PyRun_SimpleSt ring("import sys; print sys.path");
to see where Python expects to find its library (or call the Py_GetPath
function).
It returned a list of paths nearly identical to what the interactive
interpreter does -- it's on a different machine and too long to retype
here -- the interactive sys.path has an empty string as item 0, while
the embedded sys.path returns the interactive[1:n].
>You may need to call Py_SetProgramNa me (before Py_Initialize) so it can
find where the standard library resides.
Didn't do anything, alas.
>At least for testing purposes, you can copy your executable into the same
directory where Python is installed.
No can do -- it's not my machine and I don't have appropriate
privileges. Thanks for trying to help me out but I'm on a crash
deadline and it looks like I'll be doing some C parsing. Blech.
Jim
--

It's not "pretexting ", it's "lying."
Feb 12 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2571
by: Vio | last post by:
Hi, I've been trying to embed (statically) wxPy alongside an embedded py interpreter on a linux/gtk box. At one point, for some reason misc.o linking reported "multiple definitions of wxGetFreeMemory()". Since wxGetFreeMemory() seemed effectively unused in gtk, I just commented it out in misc_wrap.cpp (didn't want to patch SWIG to regenerate the wrapper code, so hacked the generated cpp source), and replaced...
3
3894
by: gerald.maher | last post by:
Hi, I am trying to excuate the follwong code: I get the following error: Here is my Lib path:
0
2707
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24 to obtain SHIP_wrap.cpp and SHIP.py; the latter contains the line "import _SHIP". I compile SHIP_wrap.cpp and a bunch of files into a DLL which I have the
2
3739
by: VMI | last post by:
In Access, when a user's going to import a fixed-width format ascii file, a window in the "Import Text Wizard" lets the user "mark" where in a string one field will begin and end (with the vertical lines that can be moved with the mouse). Can this (or something similar) be implemented in order for the user to graphically choose which part of the string will be, for example, be displayed in a MessageBox? So for example, my control would...
2
1740
by: Word Painter | last post by:
this may be more of an "html" issue, but I'll wing it. i've got a multi-language site, where the home-page of each language group features a link to a popup window that offers background info on site management. the popup is fired by a javascript function, when they click the site management link. there's also a "window close" function button so they can nuke it as they please. now, oddly, people who search for my site in the chinese...
0
1198
by: John Pye | last post by:
Hi all, I'm doing some convoluted stuff with running a python script from inside a shared library that's running inside a Tcl/Tk interpreter. It's all been going surprisingly well, up until the point where my Python script attempts to import matplotlib, which includes a reference to import md5: I get this error bubbling through:
6
2054
by: bhochstetler | last post by:
I am on a hp 11.11 machine doing a 64 bit python 2.5 build. When I get my python executable created and run it, I get the error: "import site failed" OverflowError: signed integer is greater than the maximum. This is happening in the convertsimple() routine when it tries to return a signed int:
1
1981
by: Eric Hanchrow | last post by:
(This is with Python 2.5.2, on Ubuntu Hardy, if it matters.) This seems so basic that I'm surprised that I didn't find anything about it in the FAQ. (Yes, I am fairly new to Python.) Here are three tiny files: ==== mut.py ==== import system
4
3612
YarrOfDoom
by: YarrOfDoom | last post by:
I just installed wxPython on my computer (Windows "fails-a-lot" Vista, 32bit, Python 2.6, PIL and pyOpenGL installed). However, when I try to import the wxPython module, I get this: >>> import wxPython Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import wxPython File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wxPython\__init__.py", line 7, in <module> DeprecationWarning, stacklevel=2)
0
8233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.