(Just to preface this, I am a Python noob, so parts may be stupid/less obvious to me)
I am trying to compile a Python script to exe, with the following setup.py file:

from cx_Freeze import setup, Executable

includes = ["re", "PyVMF"]

setup(
    name="Wall Tile Randomizer",
    version="1.2",
    description="Wall Tile Randomizer",
    executables=[Executable("WallRandomizer.py")],
)

The first time I ran this, I did not have the includes = ["re", "PyVMF"] line. I ran it, and got the "ImportError: no module named 're'" error when I ran the compiled exe. As suggested elsewhere, I added that line (PyVMF is another module used) I am still, however, getting the same error. What am I doing wrong?

You don't need to include re it's a python build in module and cxFreeze will find it.
If you want to include moduls you also need to modify setup.

Here is a test i did with regex,as you see i include nothing.
If it work re_test.exe will output ['fast', 'friendly']

''''
Put "my_cx_freeze.py" and "re_test.py"(your script) in same folder.
Run it from command line(cmd) or terminal linux,navigate to folder with script.
Then type python my_cx_freeze.py build
'''

#my_cx_freeze.py
from cx_Freeze import setup,Executable

includefiles = []
includes = []
excludes = []
packages = []

filename = "re_test.py"
setup(
    name = 'myapp',
    version = '0.1',
    description = 'Re test',
    author = 'None',
    author_email = 'someting@my.org',
    options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}},
    executables = [Executable(filename, base = None, icon = None)])

---

#re_test
import re

match = re.findall(r'\bf.*?\b', 'a fast and friendly dog')
print(match)
raw_input('Press enter to exit')
#input('Press enter to exit') #for python 3 use this

As you execute cx_freeze it will actually show what it includes by default. Usually re is in that list.

Also look at snippsat's include_files option.

Sorry about the slow response, had a few emergencies/deadlines in the way.
I was probably a bit unclear in the original post - my script does not use re in any way, nor do any of the modules it imports. However, I still get the re error. As suggested elsewhere, I added re to my list of includes but still does not work. My script works fine in the Python shell but it only now has problems. Here is the full output from the command line:

C:\Users\Chase\Desktop>C:/Python33/python.exe my_cx_freeze.py build
running build
running build_exe
copying C:\Python33\lib\site-packages\cx_Freeze\bases\Console.exe -> build\exe.w
in32-3.3\WallRandomizer.exe
copying C:\Windows\system32\python33.dll -> build\exe.win32-3.3\python33.dll
*** WARNING *** unable to create version resource
install pywin32 extensions first
writing zip file build\exe.win32-3.3\library.zip

  Name                      File
  ----                      ----
m BUILD_CONSTANTS
m PyVMF                     C:\Python33\PyVMF.py
m _bisect
m _bz2                      C:\Python33\DLLs\_bz2.pyd
m _codecs
m _codecs_cn
m _codecs_hk
m _codecs_iso2022
m _codecs_jp
m _codecs_kr
m _codecs_tw
m _collections
m _datetime
m _dummy_thread
m _functools
m _hashlib                  C:\Python33\DLLs\_hashlib.pyd
m _heapq
m _imp
m _io
m _locale
m _md5
m _multibytecodec
m _random
m _sha1
m _sha256
m _sha512
m _string
m _strptime
m _struct
m _thread
m _threading_local
m _warnings
m _weakref
m _weakrefset
m abc
m argparse
m atexit
m base64
m binascii
m bisect
m builtins
m bz2
m calendar
m codecs
P collections
m collections.abc
m contextlib
m copy
m copyreg
m cx_Freeze__init__         C:\Python33\lib\site-packages\cx_Freeze\initscripts\
Console3.py
m datetime
m dummy_threading
P encodings
m encodings.aliases
m encodings.ascii
m encodings.base64_codec
m encodings.big5
m encodings.big5hkscs
m encodings.bz2_codec
m encodings.charmap
m encodings.cp037
m encodings.cp1006
m encodings.cp1026
m encodings.cp1140
m encodings.cp1250
m encodings.cp1251
m encodings.cp1252
m encodings.cp1253
m encodings.cp1254
m encodings.cp1255
m encodings.cp1256
m encodings.cp1257
m encodings.cp1258
m encodings.cp424
m encodings.cp437
m encodings.cp500
m encodings.cp65001
m encodings.cp720
m encodings.cp737
m encodings.cp775
m encodings.cp850
m encodings.cp852
m encodings.cp855
m encodings.cp856
m encodings.cp857
m encodings.cp858
m encodings.cp860
m encodings.cp861
m encodings.cp862
m encodings.cp863
m encodings.cp864
m encodings.cp865
m encodings.cp866
m encodings.cp869
m encodings.cp874
m encodings.cp875
m encodings.cp932
m encodings.cp949
m encodings.cp950
m encodings.euc_jis_2004
m encodings.euc_jisx0213
m encodings.euc_jp
m encodings.euc_kr
m encodings.gb18030
m encodings.gb2312
m encodings.gbk
m encodings.hex_codec
m encodings.hp_roman8
m encodings.hz
m encodings.idna
m encodings.iso2022_jp
m encodings.iso2022_jp_1
m encodings.iso2022_jp_2
m encodings.iso2022_jp_2004
m encodings.iso2022_jp_3
m encodings.iso2022_jp_ext
m encodings.iso2022_kr
m encodings.iso8859_1
m encodings.iso8859_10
m encodings.iso8859_11
m encodings.iso8859_13
m encodings.iso8859_14
m encodings.iso8859_15
m encodings.iso8859_16
m encodings.iso8859_2
m encodings.iso8859_3
m encodings.iso8859_4
m encodings.iso8859_5
m encodings.iso8859_6
m encodings.iso8859_7
m encodings.iso8859_8
m encodings.iso8859_9
m encodings.johab
m encodings.koi8_r
m encodings.koi8_u
m encodings.latin_1
m encodings.mac_arabic
m encodings.mac_centeuro
m encodings.mac_croatian
m encodings.mac_cyrillic
m encodings.mac_farsi
m encodings.mac_greek
m encodings.mac_iceland
m encodings.mac_latin2
m encodings.mac_roman
m encodings.mac_romanian
m encodings.mac_turkish
m encodings.mbcs
m encodings.palmos
m encodings.ptcp154
m encodings.punycode
m encodings.quopri_codec
m encodings.raw_unicode_escape
m encodings.rot_13
m encodings.shift_jis
m encodings.shift_jis_2004
m encodings.shift_jisx0213
m encodings.tis_620
m encodings.undefined
m encodings.unicode_escape
m encodings.unicode_internal
m encodings.utf_16
m encodings.utf_16_be
m encodings.utf_16_le
m encodings.utf_32
m encodings.utf_32_be
m encodings.utf_32_le
m encodings.utf_7
m encodings.utf_8
m encodings.utf_8_sig
m encodings.uu_codec
m encodings.zlib_codec
m errno
m functools
m genericpath
m gettext
m hashlib                   C:\Python33\lib\hashlib.py
m heapq
m imp
P importlib
m importlib._bootstrap
m importlib.machinery
m io
m itertools
m keyword
m linecache
m locale
P logging                   C:\Python33\lib\logging\__init__.py
m math
m nt
m ntpath
m operator
m optparse
m os
m posixpath
m quopri
m random                    C:\Python33\lib\random.py
m reprlib
m stat
m string
m stringprep
m struct
m sys
m textwrap
m threading
m time
m token
m tokenize
m traceback
m types
m unicodedata               C:\Python33\DLLs\unicodedata.pyd
m wallrandomizer__main__    WallRandomizer.py
m warnings
m weakref
m zipimport
m zlib

copying C:\Python33\DLLs\_bz2.pyd -> build\exe.win32-3.3\_bz2.pyd
copying C:\Python33\DLLs\_hashlib.pyd -> build\exe.win32-3.3\_hashlib.pyd
copying C:\Python33\DLLs\unicodedata.pyd -> build\exe.win32-3.3\unicodedata.pyd

C:\Users\Chase\Desktop>cd build/exe.win32-3.3

C:\Users\Chase\Desktop\build\exe.win32-3.3>WallRandomizer.exe
Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2
7, in <module>
    exec(code, m.__dict__)
  File "WallRandomizer.py", line 1, in <module>
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in _find_a
nd_load
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1525, in _find_a
nd_load_unlocked
  File "C:\Python33\lib\random.py", line 39, in <module>
    from warnings import warn as _warn
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in _find_a
nd_load
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1525, in _find_a
nd_load_unlocked
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 497, in set_pack
age_wrapper
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 510, in set_load
er_wrapper
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 608, in _require
s_frozen_wrapper
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 713, in load_mod
ule
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 313, in _call_wi
th_frames_removed
  File "C:\Python\32-bit\3.3\lib\warnings.py", line 6, in <module>
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in _find_a
nd_load
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1525, in _find_a
nd_load_unlocked
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 497, in set_pack
age_wrapper
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 510, in set_load
er_wrapper
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 608, in _require
s_frozen_wrapper
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 713, in load_mod
ule
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 313, in _call_wi
th_frames_removed
  File "C:\Python\32-bit\3.3\lib\linecache.py", line 10, in <module>
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in _find_a
nd_load
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1525, in _find_a
nd_load_unlocked
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 497, in set_pack
age_wrapper
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 510, in set_load
er_wrapper
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 608, in _require
s_frozen_wrapper
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 713, in load_mod
ule
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 313, in _call_wi
th_frames_removed
  File "C:\Python\32-bit\3.3\lib\tokenize.py", line 28, in <module>
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in _find_a
nd_load
  File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1522, in _find_a
nd_load_unlocked
ImportError: No module named 're'

C:\Users\Chase\Desktop\build\exe.win32-3.3>

(This is for both the build and run process)

Also, the code snippets posted by snippsat compile just fine.
Does this help at all? I can also post the script as well as the module it depends on if required.

Thanks for your help!

EDIT: Fixed, although probably not with the best solution. I ended up just copying re.py to the same folder, and including it in the includefiles in the setup.py. I also had to do this with sre_compile.py, sre_parse.py, and sre_constants.py. Is there a better way to do this or am I going to have to copy all these files every time I want to compile a script?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.