Using pyinstaller on Microsoft Windows for D Rats - wb8tyw/D-Rats GitHub Wiki

Microsoft does come with a python interpreter and python library available.

The free offering from Python.org is mainly the interpreter, and for D-Rats requires modules installed from PyPi.

This means that users must first install Python, then install unsigned modules from PyPi before they can use D-Rats.

Fortunately a bundling tool is available with instructions here Pyinstaller-python Tutorial

For now the target will be Windows 7, which should allow installation on anything later.

This will need to be upgraded in the near future, as PyPi is dropping support of Windows 7, and Microsoft is dropping support of Windows older than Windows 10. Microsoft also seems to be dropping support for 32 bit Windows.

For Windows 7, we will also try to use 32 bit Python which will work on 64 bit systems for maximum portability.

First you must manually install 32 bit Python 3.8.10. This is the last version that will install on Windwows 7 32.

It comes as an executable that you run to complete the install. This will install by default in to your home directory under "AppData\Local\Programs\Python\Python38-32".

For the install, select custom install, and uncheck "tcl/tk and IDLE" and "Python test suite", and "for all users".

I left "py launcher" checked.

After install, we are going to need a virtualenv to install PyPi modules, for that we need to be in a command window instead of using the installed python application command window.

This will be in "%localappdata%\programs\Python\Python38-32"

C:\Users\malmberg>dir %localappdata%\programs\Python\Python38-32
 Volume in drive C has no label.
 Volume Serial Number is BA59-74C6

 Directory of C:\Users\malmberg\AppData\Local\programs\Python\Python38-32

10/17/2022  08:15 AM    <DIR>          .
10/17/2022  08:15 AM    <DIR>          ..
10/17/2022  08:14 AM    <DIR>          DLLs
10/17/2022  08:14 AM    <DIR>          Doc
10/17/2022  08:14 AM    <DIR>          include
10/17/2022  08:14 AM    <DIR>          Lib
10/17/2022  08:14 AM    <DIR>          libs
05/03/2021  11:54 AM            32,628 LICENSE.txt
05/03/2021  11:55 AM           955,561 NEWS.txt
05/03/2021  11:54 AM            98,992 python.exe
05/03/2021  11:54 AM            59,568 python3.dll
05/03/2021  11:54 AM         4,056,752 python38.dll
05/03/2021  11:54 AM            97,456 pythonw.exe
10/17/2022  08:15 AM    <DIR>          Scripts
10/17/2022  08:14 AM    <DIR>          Tools
05/03/2021  11:54 AM            76,176 vcruntime140.dll`

Work in progress:

C:\Users\malmberg>set pythonbin=%localappdata%\programs\Python\Python38-32

C:\Users\malmberg>%pythonbin%\python -m venv %HOMEPATH%/%COMPUTERNAME%_venv --system-site-packages

The resulting virtual env looks different from Linux.

C:\Users\malmberg>dir %COMPUTERNAME%_venv
 Volume in drive C has no label.
 Volume Serial Number is BA59-74C6

 Directory of C:\Users\malmberg\CYBERDOG_venv

10/17/2022  08:32 AM    <DIR>          .
10/17/2022  08:32 AM    <DIR>          ..
10/17/2022  08:32 AM    <DIR>          Include
10/17/2022  08:32 AM    <DIR>          Lib
10/17/2022  08:32 AM               123 pyvenv.cfg
10/17/2022  08:32 AM    <DIR>          Scripts
               1 File(s)            123 bytes
               5 Dir(s)  254,878,679,040 bytes free

C:\Users\malmberg>dir %COMPUTERNAME%_venv\Scripts
 Volume in drive C has no label.
 Volume Serial Number is BA59-74C6

 Directory of C:\Users\malmberg\CYBERDOG_venv\Scripts

10/17/2022  08:32 AM    <DIR>          .
10/17/2022  08:32 AM    <DIR>          ..
10/17/2022  08:32 AM             2,288 activate
10/17/2022  08:32 AM               977 activate.bat
10/17/2022  08:32 AM            19,332 Activate.ps1
10/17/2022  08:32 AM               368 deactivate.bat
10/17/2022  08:32 AM            97,145 pip.exe
10/17/2022  08:32 AM            97,145 pip3.8.exe
10/17/2022  08:32 AM            97,145 pip3.exe
10/17/2022  08:32 AM           430,256 python.exe
10/17/2022  08:32 AM           429,232 pythonw.exe
               9 File(s)      1,173,888 bytes
               2 Dir(s)  254,878,679,040 bytes free

And this will activate it:

C:\Users\malmberg>%COMPUTERNAME%_venv\Scripts\activate

(CYBERDOG_venv) C:\Users\malmberg>

The next step is to try running D-Rats in this environment. My D-Rats development git checkout is on a mapped drive. Normally you need to do a pip install -r requirements.txt to makes sure the virtual environment has all the dependencies.

W:
cd W:\work\d-rats\D-Rats
pip install -r requirements.txt
...
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31
629\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DPY_SSIZE_T_CLEA
N -IC:\Users\malmberg\AppData\Local\Temp\pip-install-7qdzo4cb\pygobject_64022559
87f84824bc855465c425b020 -IC:\Users\malmberg\AppData\Local\Temp\pip-install-7qdz
o4cb\pygobject_6402255987f84824bc855465c425b020\gi -Ic:\users\malmberg\cyberdog_
venv\include -IC:\Users\malmberg\AppData\Local\programs\Python\Python38-32\inclu
de -IC:\Users\malmberg\AppData\Local\programs\Python\Python38-32\include -IC:\Pr
ogram Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\inc
lude -IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.
33.31629\ATLMFC\include -IC:\Program Files\Microsoft Visual Studio\2022\Communit
y\VC\Auxiliary\VS\include -IC:\Program Files (x86)\Windows Kits\10\include\10.0.
19041.0\ucrt -IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um
-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared -IC:\Prog
ram Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt -IC:\Program Files
(x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt /Tcgi\gimodule.c /Fobuild\
temp.win32-3.8\Release\gi\gimodule.obj -FImsvc_recommended_pragmas.h
  gimodule.c
  gi\gimodule.c: fatal error C1083: Cannot open include file: 'msvc_recommended_pragmas.h': No such file or directory
  error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\V
C\\Tools\\MSVC\\14.33.31629\\bin\\HostX86\\x86\\cl.exe' failed with exit code 2
  ----------------------------------------
  ERROR: Failed building wheel for PyGObject
Failed to build PyGObject
ERROR: Could not build wheels for PyGObject which use PEP 517 and cannot be installed directly

This fails to build PyGobject. It found the Microsoft Visual Studio Community edition that was installed for building LZHUF though. So there might be some hope in getting this to install.

⚠️ **GitHub.com Fallback** ⚠️