ezuk
ezuk

Reputation: 3196

Using py2exe in a virtualenv

I have a Python script I developed within a virtualenv on Windows (Python 2.7).

I would now like to compile it into a single EXE using Py2exe.

I've read and read the docs and stackoverflow, and yet I can't find a simple answer: How do I do this? I tried just installing py2exe (via the downloadable installer), but of course that doesn't work because it uses the system-level python, which doesn't have the dependencies for my script installed. It needs to use the virtualenv - but there doesn't seem to be such an option.

I did manage to get bbfreeze to work, but it outputs a dist folder crammed with files, and I just want a simple EXE file (one file) for my simple script, and I understand Py2Exe can do this.

tl;dr: How do I run Py2Exe within the context of a virtualenv so it correctly imports dependencies?

Upvotes: 9

Views: 5223

Answers (2)

hexo
hexo

Reputation: 111

You can do that this way:

  1. Activate your virtualenv and then ...
  2. easy_install py2exe-0.6.9.win32-py2.7.exe

Upvotes: 11

g.d.d.c
g.d.d.c

Reputation: 47988

Installing py2exe into your virtual env should be straightforward. You'll need Visual Studio 2008, the express version should work. Launch a 2008 Command Prompt and Activate your virtual env. Change into the directory that contains the py2exe source and run python setup.py install. You can verify that py2exe is in the correct environment by attempting to import it from an interactive shell. I tested myself earlier today (had to install virtualenv). It works exactly as expected.

Upvotes: 1

Related Questions