Python Embedding, no correct lib

  • Thread starter moerchendiser2k3
  • Start date
M

moerchendiser2k3

Hi,

I have a serious problem with Python. I am currently trying to
implement Python into my app.
Well this works fine, but get this:

I have my own Python interpreter in a subfolder of my app. When I
start my app, PYTHONHOME is set, and an environment variable is set to
it can find the python DLL on startup.

When Python is not installed on the system everything works fine as
expected.

When I now install Python on my system (so I have two python libs now)
the system installation is the preferred one.

print sys.path prints out ['', 'C:\Windows
\system32\python26.zip', ...] and I cant explain whats going wrong
here. I expected that it just uses the System lib when it cannot find
it in the subfolder which I set in the environment variables
before.. :-(

Any ideas? Thanks a lot for help.

Bye, moerchendiser2k3
 
G

Gabriel Genellina

En Wed, 05 May 2010 09:04:06 -0300, moerchendiser2k3
I have a serious problem with Python. I am currently trying to
implement Python into my app.
Well this works fine, but get this:

I have my own Python interpreter in a subfolder of my app. When I
start my app, PYTHONHOME is set, and an environment variable is set to
it can find the python DLL on startup.

You should not define any environment variables.

You are embedding Python into your application, aren't you? That is, you
call Py_Initialize and all that stuff - you don't invoke a separate
python.exe, true?

Python tries to find its standard library looking for
[the directory containing the executable]\Lib\os.py
and a few other places. Once it finds the "Lib" directory, all other are
derived from it.
When Python is not installed on the system everything works fine as
expected.

When I now install Python on my system (so I have two python libs now)
the system installation is the preferred one.

print sys.path prints out ['', 'C:\Windows
\system32\python26.zip', ...] and I cant explain whats going wrong
here.

Such zip file doesn't even exist in a standard Python installation; but it
means that your program loaded python26.dll from the system32 directory,
not your own copy. You may want to use a .local file or a manifest; see
http://msdn.microsoft.com/en-us/library/ms811694.aspx
I expected that it just uses the System lib when it cannot find
it in the subfolder which I set in the environment variables
before.. :-(

Note that this is a Windows issue, not a Python one. You have to ensure
the Python DLL is loaded from your own directory, not the system one.

(BTW, don't set any environment variables. There is no need to do so, and
it may conflict with an existing installation. The reverse is true too: a
PYTHONPATH variable set for the "system" Python will interfere with your
private copy too. Global state is always a bad idea.)
 
M

moerchendiser2k3

En Wed, 05 May 2010 09:04:06 -0300, moerchendiser2k3  
I have a serious problem with Python. I am currently trying to
implement Python into my app.
Well this works fine, but get this:
I have my own Python interpreter in a subfolder of my app. When I
start my app, PYTHONHOME is set, and an environment variable is set to
it can find the python DLL on startup.

You should not define any environment variables.

You are embedding Python into your application, aren't you? That is, you  
call Py_Initialize and all that stuff - you don't invoke a separate  
python.exe, true?

Python tries to find its standard library looking for
[the directory containing the executable]\Lib\os.py
and a few other places. Once it finds the "Lib" directory, all other are  
derived from it.
When Python is not installed on the system everything works fine as
expected.
When I now install Python on my system (so I have two python libs now)
the system installation is the preferred one.
print sys.path prints out ['', 'C:\Windows
\system32\python26.zip', ...] and I cant explain whats going wrong
here.

Such zip file doesn't even exist in a standard Python installation; but it  
means that your program loaded python26.dll from the system32 directory,  
not your own copy. You may want to use a .local file or a manifest; seehttp://msdn.microsoft.com/en-us/library/ms811694.aspx
I expected that it just uses the System lib when it cannot find
it in the subfolder which I set in the environment variables
before.. :-(

Note that this is a Windows issue, not a Python one. You have to ensure  
the Python DLL is loaded from your own directory, not the system one.

(BTW, don't set any environment variables. There is no need to do so, and  
it may conflict with an existing installation. The reverse is true too: a  
PYTHONPATH variable set for the "system" Python will interfere with your  
private copy too. Global state is always a bad idea.)

Hi Gabriel, thanks very much for your information. I found the
solution.
This is related to this one. The order of the search path is the
explanation
why the system one is used:

http://msdn.microsoft.com/en-us/library/ms682586(VS.85).aspx

So 'Alternate Search Order' is the solution. :)

Bye, moerchendiser2k3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top