19

I'm trying to build a package from source by executing python setup.py py2exe

This is the section of code from setup.py, I suppose would be relevant:

if sys.platform == "win32": # For py2exe.
    import matplotlib
    sys.path.append("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC90.CRT")
    base_path = ""
    data_files = [("Microsoft.VC90.CRT", glob.glob(r"C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*")),

Error it shows:

*** finding dlls needed ***
error: MSVCP90.dll: No such file or directory

But I've installed "Microsoft Visual C++ 2008 Redistributable Package". I'm running 32-bit python on 64-bit Windows 8. I'm trying to build a 32-bit binaries.

Also there is no folder like this: "C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\". This is what my computer contains:

enter image description here

EDIT:

On searching for msvcp90.dll on my C:\ drive I found that they are installed in weird paths like this:

enter image description here

claws
  • 52,236
  • 58
  • 146
  • 195
  • These links may help: http://stackoverflow.com/questions/1158705/msvcp90-dll-not-found https://www.microsoft.com/en-us/download/details.aspx?id=29 – squiguy Aug 26 '12 at 06:35
  • 1
    Does this code succeed: `import ctypes; lib = ctypes.WinDLL('msvcp90.dll')` – David Heffernan Aug 26 '12 at 19:11
  • @DavidHeffernan: Yeah, this code succeeds in python shell (IDLE). After executing your code, if I run, ">>>lib" It says – claws Aug 26 '12 at 20:32
  • 1
    Looks like something funky with the py2exe then – David Heffernan Aug 26 '12 at 20:39
  • @DavidHeffernan: Do you have any further suggestion. Also where can I find that god damn `msvcp90.dll`. Its not located in the path its usually should be. – claws Aug 26 '12 at 20:47
  • 1
    I think it will be in the SxS cache. I know nothing about py2exe. Sorry. – David Heffernan Aug 26 '12 at 20:51
  • @DavidHeffernan: I believe that VS2008 is installed to SxS. In that case the only correct way to get it would be to have users install the redist, I think (or having the app installer do that). – nneonneo Aug 28 '12 at 07:09
  • @mneonneo I thought OP was simply trying to build py2exe from source – David Heffernan Aug 28 '12 at 07:13
  • Py2exe is an executable packager for Python. In a nutshell, it bundles together the interpreter, libraries, scripts and binary dependencies into a single deployable package. – nneonneo Aug 28 '12 at 08:39

4 Answers4

12

I would recommend ignoring the dependency outright. Add MSVCP90.dll to the list of dll_excludes given as an option to py2exe. Users will have to install the Microsoft Visual C++ 2008 redistributable. An example:

setup(
    options = {
            "py2exe":{
            ...
            "dll_excludes": ["MSVCP90.dll", "HID.DLL", "w9xpopen.exe"],
            ...
        }
    },
    console = [{'script': 'program.py'}]
)
nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • VS2008 redistributable? Is that some new package that I need to install? – claws Aug 28 '12 at 07:06
  • Sorry, I meant the Visual C++ 2008 redist package. I'll edit to fix. – nneonneo Aug 28 '12 at 07:07
  • 1
    If this is what it is http://www.microsoft.com/en-us/download/details.aspx?id=29. Then I've installed it and repaired it again and again. Still the problem persists – claws Aug 28 '12 at 07:19
  • 2
    You (as the packager) can solve the problem using `dll_excludes`. Your users (as the receivers of the package) will need to install the redist before using the program. Using `dll_excludes` should stop py2exe from looking for the DLL. – nneonneo Aug 28 '12 at 07:21
  • I want to ship these dlls along with the software. – claws Aug 28 '12 at 07:59
  • 2
    @claws rather than shipping the dlls, you could ship the redistributable installer and promt the user to install it. – Daniel Kinsman Sep 03 '12 at 07:24
3

(new answer, since the other answer describes an alternate solution)

You can take the files from the WinSxS directory and copy them to the C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT directory (normally created by Visual Studio, which you don't have). Copy them to get the following structure:

  +-Microsoft.VC90.CRT
  | |
  | +-Microsoft.VC90.CRT.manifest
  | +-msvcm90.dll
  | +-msvcp90.dll
  | +-msvcr90.dll

Then, you should be able to run the setup program (still excluding msvcp90.dll, as in the other answer), and it should successfully find the files under Microsoft.VC90.CRT and copy them as data files to your bundle.

See the py2exe tutorial for more information.

nneonneo
  • 171,345
  • 36
  • 312
  • 383
0

I think it has something to do with the spaces in the directory. You should try using .rstrip(). For example, put this:

directory='C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT'
directory=directory.rstrip()

You can then use the variable directory like you would have used the actual path.

This should make python able to recognize the directory where it wouldn't be able to decipher it before.

ThisIsAQuestion
  • 1,887
  • 14
  • 20
0

I used to have a huge number of problems with complication on Windows, like the issue you're facing as well as installing packages like Cython with pip install cython.

The solution that worked best for me after two weeks of pain was downloading and running the unofficial MinGW GCC binary for Windows provided here. You might want to try giving that a shot and seeing if it helps.

If you do do it, you might want to uninstall MinGW if you have it already. I don't know if that's strictly necessary, but I always did it just in case. I did have it installed side-by-side with Cygwin without any problems.

jdotjdot
  • 16,134
  • 13
  • 66
  • 118