2

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.

Jonah
  • 21
  • 1
  • It seems like it compiled without bundling the dependencies [Possible solution to bundle the dependencies](https://stackoverflow.com/questions/48757977/how-to-include-dependencies-from-venv-directory-when-running-pyinstaller-for-pro) – RaoufM Jun 23 '20 at 20:40

1 Answers1

0

Currently checking the pyinstaller documentation is supports python 2.7 and 3.5 to 3.7 are you using python 3.8 ? there is a way to make python relevant in the terminal, it may be likely when you type

pyinstaller <my python file>.py

Linux or raspbian isn't recognising that as a python library or python command at all, which is why you have to prefix it with "python -m" there are many tutorials on youtube which cover how to run python in linux terminals which will still work on raspbian. so yeah check your python version can work with pyinstaller and get back to us :D

  • Typing `python --version` gives me `Python 2.7.13`. Typing `python3 --version` gives me `Python 3.5.3`. – Jonah Jun 23 '20 at 21:23