Install wxPython With Solved ImportError

This post describes how to install wxPython on ubuntu system and helps with solved build errors while installation. This post assumes you have bare Ubuntu 18.04.3 LTS system and it is newly installed. wxPython is a opensource, cross platform, GUI toolkit for the Python programming.

This post describes in detail for how to install wxpython ubuntu 18.04 for python2 and python3. wxPython allows Python programmers to create programs highly functional graphical

user interface, simply and easily. Being cross platform with little changes it works on Microsoft windows and Linux systems. So if you have GUI application that requires to be executed on both windows and Linux wxPython is right choice for python programmers.

‘pip’ is required as a prior condition for installation of wxPython, install ‘pip’ by running following command

$ sudo apt install python-pip

As per How to install wxPython wiki guide, to install wxPython using ‘pip’ you will need to execute following command

$  pip install -U \
-f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 \
wxPython

This command after successful execution says –

Installing collected packages: six, numpy, pillow, wxPython
Successfully installed numpy-1.16.5 pillow-6.1.0 six-1.12.0 wxPython-4.0.6

Now to test the installation execute below commands

$python2
>>> import wx
>>> wx.VERSION_STRING
'4.0.1'

After executing ‘import wx’ it gives following error

Python 2.7.15+ (default, Nov 27 2018, 23:36:35) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/bhagwat/.local/lib/python2.7/site-packages/wx/__init__.py", line 17, in <module>
from wx.core import *
File "/home/bhagwat/.local/lib/python2.7/site-packages/wx/core.py", line 12, in <module>
from ._core import *
ImportError: libpng12.so.0: cannot open shared object file: No such file or directory

Problem is with above installation it is pointing to ‘ubuntu-16.04’ and we are using ‘ubuntu-18.04’, so to fix this issue just execute below command and it will install for ‘ubuntu-18.04’

$ pip install -U  -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04/ wxPython

Verify installation

$ python
Python 2.7.15+ (default, Nov 27 2018, 23:36:35) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.VERSION_STRING
'4.0.6'
>>> 

Install wxPython for python 3

Above steps works for Python 2, but how to install wxPython on python 3 or higher version. so, It seems wxPython is not fully ported for python 3 and above. But, First you will need ‘pip3’ to install wxPython for python 3.

$ sudo apt install python3-pip

So, This will install python3.6-dev and python3-dev, and once ‘pip3’ is installed simply execute following command

$  pip3 install wxPython

This command is failing with following error

    File "build.py", line 30, in <module>
import pathlib2
ModuleNotFoundError: No module named 'pathlib2'
Command '"/usr/bin/python3" -u build.py build' failed with exit code 1.
----------------------------------------
Failed building wheel for wxPython
Running setup.py clean for wxPython
so install 'pathlib2' by running following command
$ pip3 install pathlib2
If above command fails use below command to upgrade 'wxPython' 
$ python3 -m pip install --upgrade --pre -f https://wxpython.org/Phoenix/snapshot-builds/ wxPython

Now if you got following errors:
python-config : not found
Checking for library python3.7m in LIBDIR : not found
Checking for library python3.7m in python_LIBPL : not found
Checking for library python3.7m in $prefix/libs : not found
Checking for library python3.7m in LIBDIR : not found
Checking for library python3.7m in python_LIBPL : not found
Checking for library python3.7m in $prefix/libs : not found
Checking for library python37 in LIBDIR : not found
Checking for library python37 in python_LIBPL : not found
Checking for library python37 in $prefix/libs : not found
Checking for header Python.h : Distutils not installed? Broken python installation? Get python-config now!
The configuration failed

Install new python3.7.4 if above error still there then uninstall wxpython.

$sudo apt-get install python-dev
$pip uninstall wxpython
$sudo apt install libgtk-3-dev

Still, If you are getting following error:
File “/home/.local/lib/python3.8/site-packages/wx/core.py”, line 12, in <module>
from ._core import *
ImportError: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory
To solve:

$sudo apt-get install git curl libsdl2-mixer-2.0-0 libsdl2-image-2.0-0 libsdl2-2.0-0
$pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 wxPython

Thats it happy to help you during install wxpython ubuntu 18.04 for python2 and python3. Keep reading and comment out your experiences.

How To Install Ionic Cordova With First Application

Ionic framework is one of the popular development environment for mobile applications. Ionic is popular because of its open source mobile UI toolkit for developing rich cross-platform mobile applications. Cross platform meaning, apps developed using Ionic with single codebase can be executed from iOS(iPhones, iPad), Android and webserver(desktop Applications). It uses technologies like HTML, CSS, Javascript, NodeJS, To start with your first Ionic Application, you need to install Ionic framework. This post describes about installation of Ionic and its required components, running first Ionic application and how to run android application in ionic framework.

Installation

Follow below steps for Ionic framework installation. Assuming you are using fresh Ubuntu system and ‘npm’ is not installed on system, first install ‘npm’ – node package manager for javascript.

$sudo apt-get install npm 

This will install ‘npm’ package. Now download and install Ionic framework on your Ubuntu machine.

$sudo npm install -g ionic
$ionic -v 
5.2.5

We will need node.js, installation step for nodejs is as follows

$sudo apt-get install nodejs

Now install cordova- Apache Cordova is a mobile application development framework and runs on node.js

$sudo npm install -g cordova

Hello Ionic

For creating your first Ionic application follow below steps.

ionic start myapp tabs      #for creating tabs application
ionic start myapp blank     #for creating blank application
ionic start myapp slidemenu #for creating slidemenu application

Now navigate to ‘myapp’ directory and publish your first ionic application. It is as simple as that but for the first time you might encounter following errors – ‘ng run app:serve –host=localhost –port=8100 [ng] An unhandled exception occurred: Could not find module “@angular-devkit/build-angular” from “/home/hello/hello”. [ng] See “/tmp/ng-SmeTji/angular-errors.log” for further details.’

If you get so just un-install and re-install Ionic framework with above mentioned steps.

Now publish application on web-browser

$ionic serve

Run Android Application in Ionic Framework

While there advantages of using Ionic framework over android SDK, but lets not go there and stick to Ionic framework for the simplicity of this post :-).

First step is we need to add platform to the application ie in ‘myapp’ folder execute following command to add android platform

$ionic cordova  platform add android

ionic cordova run android
[ERROR] Sorry! ionic cordova run can only be run in an Ionic project directory.

If this is a project you'd like to integrate with Ionic, run ionic init.
$ionic init
Then build application and execute it 
$ionic cordova build android
$ionic cordova run android
or 
$ionic cordova emulate android

ng run app:ionic-cordova-build –platform=android An unhandled exception occurred: EACCES: permission denied, unlink ‘/home/myapp/www/0-es2015.js’ See “/tmp/ng-QTKII3/angular-errors.log” for further details. [ERROR] An error occurred while running subprocess ng. ng run app:ionic-cordova-build –platform=android exited with exit code 127. Re-running this command with the –verbose flag may provide more information.

These are first time errors and occurred because we have not sent $PATH.

Adding SDK,JDK and Gradle path in ionic project

1. export ANDROID_HOME=/home/Android/Sdk

2. export JAVA_HOME=/home/android-studio-ide-182.5264788-linux/android-studio/jre export

3. export GRADLE_HOME=”/home/gradle/gradle-5.5.1/bin”

4. export PATH=”$PATH:$ANDROID_HOME:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$GRADLE_HOME”

5. echo $ANDROID_HOME

6. echo $JAVA_HOME

7. echo $PATH

With this now you can execute android application in Ionic Framework.