py2exe missing Modules (_posixshmem, bcrypt, readline, resource)

  cryptography, fernet, py2exe, python, python-3.x

I am developing a simple ransomware script for my bachelor thesis to see how different firewall manufacturer solved threat protection/prevention.
I wrote a simple python script using cryptography.fernet to generate a key and encrypt some example files.
To run my script on a testmachine which haven’t installed python I need to build a .exe and execute it. I have tried different Modules for example pyinstaller but the windows defender immediatly triggered an alert. However I managed to solve this problem using py2exe.
I have created the python script and everything works perfectly until I am building the .exe file.

I am receiving 4 errors when I execute following command: python setup.py py2exe

4 missing Modules
-----------------
? _posixshmem    imported from multiprocessing.resource_tracker, multiprocessing.shared_memory
? bcrypt         imported from cryptography.hazmat.primitives.serialization.ssh
? readline       imported from cmd, code, pdb
? resource       imported from test.support

For some reason the .exe file will be build in dist folder but do not work properly when I start execute the file. The console appears for a millisecond and disappears. The example files are are still readable. I tried to comment out almost everything but I still have the same problem. I think some of the above used modules are not compatible with py2exe…

My setup.py is:

from distutils.core import setup
import py2exe
import os
import time
import getpass
import pathlib
import ctypes
from cryptography.fernet import Fernet

setup(console=['dll32.py'])

I am using Python 3.9.4

Thank you for your time.

Source: Python-3x Questions

LEAVE A COMMENT