Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Feb 5, 2018

Python code to exe (Windows)

PyInstaller helps you convert your python code to executable software package.

Our test environment: Windows 7, Python 3.6

Create your python code file (hello.py)
print("Hello World!")
Download PyInstaller via pip
pip install pyinstaller
Run PyInstaller with python code file parameter on console
"C:\Program Files\Python36\Scripts\pyinstaller.exe" hello.py
You will see some commands on the screen. A few seconds later it will finish building. Build time is dependent your code (referenced packages).

Check dist folder for distribution copy of your application (hello.exe)

Size of the folder for hello.py is around 11mb.

I tried also py file with reference of cv2 library. Build time is around 30seconds and folder size becomes 157mb.

Oct 16, 2017

Install opencv package in Python

Opencv is very popular library on all platforms. This article explains how to install opencv package for Python. This will give you a general idea about installing any library in Python environment.

In code samples you will see cv2 library is imported.
import cv2
If you run sample code without installing opencv you will get following error.
Traceback (most recent call last):
  File "pythonface.py", line 2, in
    import cv2
ImportError: No module named cv2

Installing python package from online repository is very easy in python. You can search for a package in PyPI (Python Package Index) interface.

Type opencv to search box in pypi webpage (https://pypi.python.org/pypi)

This will give you a long list which contains your keyword.
List cropped for blog post.

Finding right package may be hard in this list. You can find package names from original sources of specific libraries.

If you click "opencv-python 3.3.0.10" from the list (https://pypi.python.org/pypi/opencv-python/3.3.0.10) you will see installation and usage guide.

On docs.opencv.org you can see library name as opencv-python:
OpenCV-Python is the Python API for OpenCV, combining the best qualities of the OpenCV C++ API and the Python language.
Use following command to install opencv library to your computer from PyPI.
pip install opencv-python
Now you are ready to use opencv functions.

If you can't find opencv-python package in your installation you can download source codes and run commands according to your environment. This link will give you an idea about sequence of this work.