I created a python script that I would like to compile into an executable on my raspberry pi, but my unfamiliarity with linux is getting in the way. Why am I getting errors when running the executable that pyinstaller creates when my script runs fine in terminal otherwise?
To check if the script would run properly on my pi, I navigated to the correct directory in terminal and ran the following.
python <my python file>.py
I didn’t receive any errors. It uses the requests library to make http post requests and the opencv library for image compression. Seeing as it ran successfully, I attempted to install pyinstaller and use it to compile my script into a linux executable. I installed it with the following.
pip install pyinstaller
It seemingly installed with no errors. Unfortunately I tried the following code to start compiling, but ran into an error.
pyinstaller <my python file>.py
This gave me the error “command not found”. Instead I tried the following code to get it running.
python -m PyInstaller <my python file>.py
This ran successfully (even though I don’t fully understand the difference) and I navigated to the new directory named dlist to find the executable. I found the executable file, but now I found a new problem. When I navigate to the dlist directory in terminal and run the executable, I get the following error.
Traceback (most recent call last):
File "/home/Jonah/Downloads/ocr_with_api.py", line 3, in <module>
import requests
File "/tmp/pip-unpacked-wheel-RITpob/PyInstaller/loader/pyimod03_importers.py", line 391, in load_module
File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 60, in <module>
from .packages.urllib3.exceptions import DependencyWarning
ImportError: No module named urllib3.exceptions
[6374] Failed to execute script ocr_with_api
Could anyone help me out? For awhile the end of the error message was saying no module named requests but it seems like I may have fixed that while also getting a new error saying that I don’t have a module named urllib3.exceptions... I’m really confused.
FYI - When I type python --version
in terminal, it tells me that I'm using a version of Python 2. When I type python3 --version
in terminal, it tells me that I'm using the the most up to date version. I don't have a problem with compiling my script in Python 2 as long as it runs okay and I'm assuming that I just need to type python3 and pip3 instead of python and pip in terminal respectively in order to use the python 3 installation.