473,396 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

msvcp71.dll and Python 2.4 C++ extensions

Hi,

are there any guidelines about what to do if a Windows extension for
Python 2.4 requires the C++ runtime (msvcp71.dll)? If I want to
distribute a binary installer of an extension that contains C++ code,
should I really include the msvcp71.dll in the package? It doesn't
sound like a good idea to me if every package places another copy of
this dll somewhere in the Python directory.
Python 2.4 does install the C runtime (msvcr71.dll) in the Windows
system32 directory, doesn't it? (btw, shouldn't this be installed in
the Python directory instead?) So would it be possible that future
Python releases would also install the C++ runtime? I think it's
better if the dll would only be installed once by Python instead of
several times by every extension that uses C++.

Currently, I do not package the C++ runtime and leave it up to the
user to install the dll if it isn't already somewhere on his system.
But this really is not a satisfying solution...

- Matthias -

Jul 18 '05 #1
3 3750
Matthias Baas wrote:
are there any guidelines about what to do if a Windows extension for
Python 2.4 requires the C++ runtime (msvcp71.dll)?
No; it should "just work fine". The standard guidelines apply, of
course: never try to mix different versions of similar DLLs.
If I want to
distribute a binary installer of an extension that contains C++ code,
should I really include the msvcp71.dll in the package?
If you cannot expect your users to have that file, you should distribute
it. Make sure you have read and understood the Microsoft license
concerning the file.
It doesn't
sound like a good idea to me if every package places another copy of
this dll somewhere in the Python directory.
Why not? If your installer follows Windows logo compliance rules, it
should check whether the DLL is already present; if it is, it should
check whether the version installed is newer than the one it would
install, and if so, should skip installation.
Python 2.4 does install the C runtime (msvcr71.dll) in the Windows
system32 directory, doesn't it?
It depends. If this is an allusers installation, it does so. For a
per-user installation, the user might not have sufficient privileges
to install into system32, so the installer won't install it there.
(btw, shouldn't this be installed in
the Python directory instead?)
No. If you install the DLL into the Python directory, Python
will not work anymore because python24.dll (installed into system32)
will not find this DLL. If you then also move python24.dll into
the Python directory, COM components that require python24.dll will
fail to run.
So would it be possible that future
Python releases would also install the C++ runtime?
Why should it? Nothing in the Python distribution requires C++.
I think it's
better if the dll would only be installed once by Python instead of
several times by every extension that uses C++.
Why is that better? The DLL versioning rules, and the shared DLL
refcounting mechanisms will make sure that the installation works
just fine.
Currently, I do not package the C++ runtime and leave it up to the
user to install the dll if it isn't already somewhere on his system.
But this really is not a satisfying solution...


Then you should probably include the DLL, or rewrite your extension
to not use C++.

Regards,
Martin
Jul 18 '05 #2
On Tue, 01 Feb 2005 00:14:30 +0100, "Martin v. Löwis"
<ma****@v.loewis.de> wrote:
are there any guidelines about what to do if a Windows extension for
Python 2.4 requires the C++ runtime (msvcp71.dll)?


No; it should "just work fine". [...]


I fully agree with that. :) And that was actually the reason why I
posted here, because in my case it did not just work fine...
It doesn't
sound like a good idea to me if every package places another copy of
this dll somewhere in the Python directory.


Why not? If your installer follows Windows logo compliance rules, it
should check whether the DLL is already present; if it is, it should
check whether the version installed is newer than the one it would
install, and if so, should skip installation.


I'm creating the installer via the distutils by calling "setup.py
bdist_wininst". How can I configure distutils to have it create an
installer that does the above things?

How should an installer check if a DLL is already present? Are DLLs
registered with Windows so I can query a database? Or should the
installer search for the DLL in the directories specified in the PATH
variable and see if the DLL is there?
And what's the preferred location for such a DLL? Should it be placed
in a local directory that only belongs to the package or in a
directory where other C++ extension packages might also be able to use
it? But where would this be then? The Windows system directory seems
to be discouraged by Microsoft:

"An application should use and redistribute msvcr71.dll, and it should
avoid placing a copy or using an existing copy of msvcr71.dll in the
system directory. Instead, the application should keep a copy of
msvcr71.dll in its application directory with the program executable."
(see
http://msdn.microsoft.com/library/de..._libraries.asp)
I suppose the same applies for msvcp71.dll.
Python 2.4 does install the C runtime (msvcr71.dll) in the Windows
system32 directory, doesn't it?


It depends. If this is an allusers installation, it does so. For a
per-user installation, the user might not have sufficient privileges
to install into system32, so the installer won't install it there.


Ah, ok. And yes, I did a "all users" installation.
(btw, shouldn't this be installed in
the Python directory instead?)


No. If you install the DLL into the Python directory, Python
will not work anymore because python24.dll (installed into system32)
will not find this DLL. If you then also move python24.dll into
the Python directory, COM components that require python24.dll will
fail to run.


ok, I see.
So would it be possible that future
Python releases would also install the C++ runtime?


Why should it? Nothing in the Python distribution requires C++.


Well, yes, I know. But I don't see Python as a standalone application.
One of the great things about Python is that there are so many
extension modules for every kinds of purposes. So, making available
the C++ runtime would just pave the way for more of those extension
modules by making it easier to distribute binary packages that are
implemented in C++.
I think it's
better if the dll would only be installed once by Python instead of
several times by every extension that uses C++.


Why is that better? The DLL versioning rules, and the shared DLL
refcounting mechanisms will make sure that the installation works
just fine.


I was referring to the possibility that the DLL might get installed
several times at several different locations which would be a waste of
disk space. If there's only one file, then I agree with the above
(however, what happens if I uninstall one package and this package
removes the DLL even when there are other packages installed that
still require the DLL?).
Currently, I do not package the C++ runtime and leave it up to the
user to install the dll if it isn't already somewhere on his system.
But this really is not a satisfying solution...


Then you should probably include the DLL, or rewrite your extension
to not use C++.


I'm afraid the latter will hardly ever be an option... ;)

For one smaller package I was compiling I solved the problem by
linking against the static versions of the C/C++ runtime. This will
also satisfy the "It-Should-Just-Work" constraint... :) (however,
there still could be situations where this is not possible (the
sources might not be available, for example)).

- Matthias -

Jul 18 '05 #3
Matthias Baas wrote:
I'm creating the installer via the distutils by calling "setup.py
bdist_wininst". How can I configure distutils to have it create an
installer that does the above things?
Ah, I see. Unfortunately, bdist_wininst is not capable of doing
a Windows logo compliant installation (with proper versioning checks,
shared dll reference count, etc) of a DLL. You will have to find
a different technology to distribute your application - or make sure
you copy the DLL in a place where it previously did not exist.
How should an installer check if a DLL is already present?
It should check if the file exists. If it exists, it should check
the version number of the file (there are APIs for that available),
and if the language of the installed DLL differs from the language
of the package's DLL. If the new DLL is somehow "better" (newer
version, or same version, different language, and user requested
overwriting), it should replace the DLL.
Are DLLs registered with Windows so I can query a database?
To some degree. If the software is uninstalled, the installer should
remove the file. If the file was already present at installation time,
removal may break other software. Therefor, there is a registry entry
for each path name that is a reference count, under

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\SharedDLLs

If you expect that the file is already there, you need to use that
mechanism.
Or should the
installer search for the DLL in the directories specified in the PATH
variable and see if the DLL is there?
No. There is no problem at all to install the same DLL multiple times,
in different places. In fact, Microsoft discourages shared DLLs, and
recommends that each package should install its own copy.

Windows will look for a DLL in
- the directory of the EXE
- the current working directory
- system32
- windows
- PATH

In your case, putting the C++ DLL into the directory containing
python.exe might be sufficient. The safest thing, of course, is to
put the DLL into system32 - in which case you *have* to install it
shared.
"An application should use and redistribute msvcr71.dll, and it should
avoid placing a copy or using an existing copy of msvcr71.dll in the
system directory. Instead, the application should keep a copy of
msvcr71.dll in its application directory with the program executable."
Yes. This means to install it into the directory containing python.exe.
Unfortunately, this does not work if your extension is then used in
an embedded Python, e.g. one running as a COM object. In this case,
python.exe will not be the main executable, but, say, outlook.exe will
be. So Microsoft's recommendation to install the DLL into the EXE
directory is flawed for COM and other embedded cases. This is
precisely the reason why the Python installer installs both python24.dll
and msvcr71.dll into system32.
Well, yes, I know. But I don't see Python as a standalone application.
One of the great things about Python is that there are so many
extension modules for every kinds of purposes. So, making available
the C++ runtime would just pave the way for more of those extension
modules by making it easier to distribute binary packages that are
implemented in C++.
I think we agree that building and running such an extension is not
a problem - it just works.

Distributing such an extension is indeed a problem, as bdist_wininst
does not support this case properly.

I'll plan to write a bdist_msi one day, which should handle DLL
installation better as much of the magic required is built into
Windows Installer.
I was referring to the possibility that the DLL might get installed
several times at several different locations which would be a waste of
disk space. If there's only one file, then I agree with the above
(however, what happens if I uninstall one package and this package
removes the DLL even when there are other packages installed that
still require the DLL?).
The other packages will also have added to the shared reference counter.
Uninstalling will only DECREF the counter, and the file will be removed
only when the counter goes to zero.
For one smaller package I was compiling I solved the problem by
linking against the static versions of the C/C++ runtime. This will
also satisfy the "It-Should-Just-Work" constraint... :) (however,
there still could be situations where this is not possible (the
sources might not be available, for example)).


You should make sure to use the DLL version of the C runtime. Otherwise,
you will be mixing multiple C runtimes (one that python24.dll links
with, and one linked statically into your extension); this might cause
troubles (such as memory leaks and crashes).

Regards,
Martin
Jul 18 '05 #4

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

Similar topics

49
IDE
by: Thomas Lindgaard | last post by:
Hello I am probably going to start a war now... but so be it :) I just want to hear what all you guys who eat pythons for breakfast use for python coding. Currently I use Kate, but I would...
47
by: Michael Scarlett | last post by:
There is an amazing article by paul graham about python, and an even better discussion about it on slashdot. The reason I point this out, is the more I read both articles, the more I realised how...
7
by: Scott | last post by:
I've installed Python 2.4 under WinXP and am attempting to create an extension module using the steps outlined here: http://python.org/doc/2.4/ext/win-cookbook.html I'm specifically trying to...
5
by: Fuzzyman | last post by:
Python 2.4 is built with Microsoft Visiual C++ 7. This means that it uses msvcr7.dll, which *isn't* a standard part of the windows operating system. This means that if you build a windows installer...
8
by: Saravanan | last post by:
Hello, Im running Python Application as a Windows Service (using windows extensions). But, sporadically the application crashes (crash in Python23.dll) and this stops the service. This problem...
1
by: Petr Prikryl | last post by:
Do you think that the following could became PEP (pre PEP). Please, read it, comment it, reformulate it,... Abstract Introduction of the mechanism for language extensions via modules...
4
by: vedrandekovic | last post by:
Hi, I have already install Microsoft visual studio .NET 2003 and MinGw, when I try to build a extension: python my_extension_setup.py build ( or install ) , I get an error: LINK : fatal...
15
by: kyosohma | last post by:
Hi, I am trying to get a small group of volunteers together to create Windows binaries for any Python extension developer that needs them, much like the package/extension builders who volunteer...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.