英文:
Pyinstaller comes with errors when importing backtesting.py module
问题
I am using Windows 11 for Python code development. I have a large Python program that uses the backtesting.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 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 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:\Users\menb\Documents\tests\test3\test3>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 "PyInstaller\loader\pyimod02_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 "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "backtesting\backtesting.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 "PyInstaller\loader\pyimod02_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 an unhandled exception!
Any help to solve this problem is highly appreciated.
英文:
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:\Users\menb\Documents\tests\test3\test3>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 "PyInstaller\loader\pyimod02_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 "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "backtesting\backtesting.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 "PyInstaller\loader\pyimod02_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.
答案1
得分: 1
我能够成功编译和运行你的示例中的两行代码,使用 pyinstaller。
import backtesting
print("Hello")
重现步骤:
- 创建一个新的虚拟环境并安装 pyinstaller 和 backtesting。
- 创建一个名为
main.py
的文件,其中包含你的示例代码。 - 运行以下命令:
pyinstaller -F --collect-all backtesting main.py
或者
- 运行以下命令:
pyinstaller -F --collect-all backtesting --collect-all bokeh --collect-all xyzservices main.py
然后运行:dist/main.exe
输出:
Hello
英文:
I was able to successfully compile and run the two lines from your example using pyinstaller.
import backtesting
print ("Hello")
Steps to reproduce.
- create a new virtual enviornment and install pyinstaller and backtesting
- create
main.py
with your example code. - run
pyinstaller -F --collect-all backtesting main.py
or
pyinstaller -F --collect-all backtesting --collect-all bokeh --collect-all xyzservices main.py
then run: dist/main.exe
OUTPUT:
Hello
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论