Pyinstaller comes with errors when importing backtesting.py module

Question:

I am using Windows 11 for Python code development. I have a large Python program that uses the backteting.py module. The program works fine when running it using Visual Studio Code or executing it in the console. However, when I create an EXE file using the Pyinstaller, the EXE file does not work. I managed to reduce the code to two instructions (see below) and yet the EXE program does not work.

import backtesting
print ("Hello") 

I am getting the following warnings when I run the Pyinstaller.

115289 WARNING: Library user32 required via ctypes not found
115301 WARNING: Library msvcrt required via ctypes not found 

In addition, I am also getting the following errors when I run the EXE file.

C:UsersmenbDocumentsteststest3test3>test3
Traceback (most recent call last):
  File "test3.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstallerloaderpyimod02_importers.py", line 352, in exec_module
  File "backtesting__init__.py", line 60, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstallerloaderpyimod02_importers.py", line 352, in exec_module
  File "backtestingbacktesting.py", line 32, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstallerloaderpyimod02_importers.py", line 352, in exec_module
  File "backtesting_plotting.py", line 43, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\menb\Documents\tests\test3\test3\backtesting\autoscale_cb.js'
[33336] Failed to execute script 'test3' due to unhandled exception!

Any help to solve this problem is highly appreciated.

Asked By: Menachem

||

Answers:

I was able to successfully compile and run the two lines from your example using pyinstaller.

import backtesting
print ("Hello") 

Steps to reproduce.

  1. create a new virtual enviornment and install pyinstaller and backtesting
  2. create main.py with your example code.
  3. run
    pyinstaller -F --collect-all backtesting main.py

or

  1. pyinstaller -F --collect-all backtesting --collect-all bokeh --collect-all xyzservices main.py

then run: dist/main.exe

OUTPUT:

Hello
Answered By: Alexander