Skip to content

Install in Xubuntu 18.04

Padmal edited this page May 14, 2019 · 6 revisions

Xubuntu Logo

πŸ“š PSLab Python library in Xubuntu

pslab-python library can be installed in a Xubuntu PC. This installation process mentioned here was tested on a virtual machine running Xubuntu 18.04 operating system. Before we can install the library, we need root permission throughout the installation and a few dependencies libraries pre-installed. Once all the libraries are set, we can install and use pslab-python library.


πŸ“œ Table of Contents


πŸ“˜ Quick Install using script

In order to make installation easier, we have prepared a script to download and install all dependencies and libraries automatically. In order to execute that, download the installation script and execute it following the instructions given below.

πŸ“– Download the installer script

Open terminal window by pressing CTRL+Alt+T keys and navigate to a folder where you have full access. Download the script using following command:

$ wget https://raw.github.com/fossasia/pslab-desktop-apps/master/Installers/pslab-python-installer-xubuntu-1804.sh

Once the download is completed, make the installer script an executable.

chmod +x pslab-python-installer-xubuntu-1804.sh

Now execute the script using following command and observe the installation. You may be asked to enter root password to install libraries. In such cases, type your computer password and press Enter.

./pslab-python-installer-xubuntu-1804.sh

πŸ“˜ Dependencies and Pre-setup

This library is based on newer Python versions. It might or might not work with Python 2 versions. The library interacts with a Pocket Science Lab device over a USB port. It does a lot of scientific calculations to get the results out. These features require following libraries and systems pre-installed and configured to function properly.

  1. Python 3.5 or above πŸ“Œ
  2. Pip 19.0.3 or above πŸ“Œ
  3. NumPy 1.16.3 or above πŸ“Œ
  4. PySerial 3.4 or above πŸ“Œ
  5. SetupTools 35.0.2 or above πŸ“Œ
  6. Git 2.17.1 or above πŸ“Œ
  7. Make 4.1 or above πŸ“Œ

πŸ“– Install and configure Python 3

This step will guide you through setting up the correct Python version to run PSLab Python app


>>> Check for installed python versions

Before we proceed any further, check if the python version already installed is meeting the requirement. This can be done by typing the following command in terminal window. Open terminal window by pressing CTRL+Alt+T and type;

$ python3 --version

This should output something similar to:

Python 3.6.7

If this number is greater than 3.5, then we do not need to install python again. Skip to the section where we configure python path.


>>> Install Python 3

If the Python version found in "Check for installed python versions" does not meet dependency requirement, there are few options to install a correct version. We will use original source to install Python 3.7.3 version. Type the following command to download the setup files and extract it.

$ wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
$ tar -xvf Python-3.7.3.tgz

Before we move further, it is recommended to install the following libraries to support Python 3.7. Install them by typing following commands in terminal

$ sudo apt-get update && sudo apt-get install gcc zlib1g-dev libffi-dev -y

Then we can proceed with the installation. Move into the extracted source code folder and execute the configure command as follows:

$ cd Python-3.7.3
$ ./configure 

This could take a while setting up the installation. Once that is complete, execute the following set of commands in sequence to install Python 3.7.3

$ make
$ make install

If there comes an error saying command make not found, install it using:

$ sudo apt-get install make

Once the installation is complete, check Python version to see if has upgraded to 3.7.3 version. Try following commands once again to check whether the new Python versions are now set correctly.

$ python3 --version
Python 3.7.3
$ sudo python3 --version
Python 3.7.3

If both the versions are same and greater than 3.5, we have successfully completed step one installing and configuring Python 3..

πŸ“– Install Pip

This step will guide you through setting up Pip, a python package manager that is used in downloading and setting up other dependencies.


>>> Install Pip from apt package manager

Easiest method to install Pip is using apt package manager. Type the following command in terminal window.

$ sudo apt-get update && sudo apt-get install python3-pip

It is good to upgrade the pip package before we finish up this step. Type the following command in terminal window.

$ python3 -m pip install --upgrade pip

This would exit with a result similar to an ending like:

Successfully installed pip-19.1.1

If this throws an error similar to following with an error:

...
pip is configured with locations that require TSL/SSL, however the ssl module in Python is not available.
...

Try installing some packages to fix that issue and reinstall Python 3.7.3 following instructions provided in "Install Python 3" and do not install pip3 separately but do only the upgrade part mentioned in "Install Pip from apt package manager";

$ sudo apt-get install libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.5 libgdm-dev libdb4o-cil-dev libpcap-dev

and reattempt the previous pip upgrade step. With that being completed, next step is to install other dependency libraries.

πŸ“– Install NumPy

This step will guide you through installing NumPy Python package.


>>> Install NumPy from python package manager (pip)

Run the following command in terminal window to install NumPy from Python package manager.

$ sudo python3 -m pip install numpy

If the output is something similar to the following and the version number is above 1.16, that means NumPy is already available in our system.

Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (1.16.3)

If the version number is below 1.16, upgrade the NumPy library by running the following command in terminal:

$ sudo python -m pip install numpy --upgrade

After NumPy, install PySerial library

πŸ“– Install PySerial

This step will guide you through installing PySerial Python package.


>>> Install PySerial from python package manager (pip)

Run the following command in terminal window to install PySerial from Python package manager.

$ sudo python -m pip install pyserial

If the output is something similar to the following and the version number is above 3.4, that means PySerial is already available in our system.

Requirement already satisfied: pyserial in /usr/local/lib/python3.7/dist-packages (3.4)

If the version number is below 3.4, upgrade the PySerial library by running the following command in terminal:

$ sudo python -m pip install pyserial --upgrade

Last dependent library to install is Python SetupTools.

πŸ“– Install SetupTools

This step will guide you through installing SetupTools Python package.


>>> Install SetupTools from python package manager (pip)

Run the following command in terminal window to install PySerial from Python package manager.

$ sudo python -m pip install setuptools

If the output is something similar to the following and the version number is above 35.0.2, that means SetupTools is already available in our system.

Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (39.0.1)

If the version number is below 35.0.2, upgrade the SetupTools library by running the following command in terminal:

$ sudo python -m pip install setuptools --upgrade

πŸ“– Install Git

This step will guide you through installing Git version controlling tool.


>>> Install Git from apt package manager

Run the following command in terminal window to install git from apt package manager.

$ sudo apt-get install git

πŸ“– Install Make

This step will guide you through installing Make build tool.


>>> Install Make from apt package manager

Run the following command in terminal window to install make from apt package manager.

$ sudo apt-get install make

That's all the dependencies required by PSLab Python library.


πŸ“˜ Install PSLab Python library

PSLab Python library is hosted in a GitHub repository. Link to the repository is https://github.com/fossasia/pslab-python. In this section, we will download the source code and install the library in system.

πŸ“– Clone or Download pslab-python

This step will guide you through downloading/cloning the source code for pslab-python library. There are two options to get the library files into computer. One is to use git to clone the repository. Second is to download the source as a zip file from GitHub website.


>>> Clone from main repository

The production source code is hosted in the main branch of pslab-python GitHub repository. In order to close the source code, run the following command in terminal window.

$ git clone -b master https://github.com/fossasia/pslab-python.git

This will download the source code into a folder named pslab-python


>>> Download from main repository

If a user chose not to clone, but to download a release instead, do so by downloading the latest release in releases.

πŸ“– Install pslab-python from source

PSLab Python library uses a makefile to install the library in correct location.

>>> Full clean up

If you encounter any instances where there are any corrupted PSLab library instances installed previously causing errors when using the library, run the following command in a terminal:

$ make fullcleanup

It will look for installed PSLab instances, both python library and desktop libraries and prompt you to verify if the files are fine to be deleted.

/usr/local/lib/python3.7/site-packages/PSL
/usr/local/lib/python3.7/site-packages/PSL_Apps
/usr/local/lib/python3.7/site-packages/PSL-1.1.0-py3.7.egg-info
/usr/local/lib/python3.7/site-packages/PSL_Apps-1.1.0-py3.7.egg-info
/usr/share/pslab/PSL_Resources
/usr/share/pslab
/opt/pslab-desktop
/opt/pslab-python
/usr/local/bin/Experiments
Confirm if you want to remove all these files.. [Y/N]

If you're certain that there are no other system files in it, execute the following command. Go through the list of folders to double check and press Y to confirm.

>>> Normal installation

Now run the following commands in sequence to complete the installation.

$ sudo make clean

This will clean up the system to remove any previous pslab-python versions installed.

$ make all

This command will build the source code and prepare it for installation

$ sudo make install

This will perform the installation and will output a result similar to:

...
byte-compiling /usr/local/lib/python3.5/dist-packages/PSL/sensorlist.py to sensorlist.cpython-35.pyc
byte-compiling /usr/local/lib/python3.5/dist-packages/PSL/sciencelab.py to sciencelab.cpython-35.pyc
byte-compiling /usr/local/lib/python3.5/dist-packages/PSL/analyticsClass.py to analyticsClass.cpython-35.pyc
byte-compiling /usr/local/lib/python3.5/dist-packages/PSL/packet_handler.py to packet_handler.cpython-35.pyc
running install_egg_info
running egg_info
creating PSL.egg-info
writing requirements to PSL.egg-info/requires.txt
writing top-level names to PSL.egg-info/top_level.txt
writing PSL.egg-info/PKG-INFO
writing dependency_links to PSL.egg-info/dependency_links.txt
writing manifest file 'PSL.egg-info/SOURCES.txt'
reading manifest file 'PSL.egg-info/SOURCES.txt'
writing manifest file 'PSL.egg-info/SOURCES.txt'
Copying PSL.egg-info to /usr/local/lib/python3.5/dist-packages/PSL-1.1.0.egg-info
running install_scripts
# rules for udev
mkdir -p /lib/udev/rules.d
install -m 644 99-pslab.rules /lib/udev/rules.d/99-pslab

If you encounter any errors, please double check if all the dependencies are installed and the versions are matched. If the problem is still persisting, please drop us a message in pslab-gitter or pslab-google-group


πŸ“˜ Validate installation and Debug

It should be noted that we have installed this library to work with a specific Python version. In order to run and test the library, we should use the same Python version. This can be verified by following steps.

πŸ“– Verify pslab-python library

The availability of this library can be verified by trying to import it in a Python script. We can do that by opening a Python terminal and executing an import statement.

Type the following command in a terminal window to open up the correct Python version:

$ python3

This will open up a Python console and the version will be displayed at top. Double check if this was the version we installed pslab-python library to. Type the following Python statement and verify no error is thrown.

Python 3.7.3 (default, May 13 2019, 22:45:59) 
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PSL import sciencelab

If the prompt moved to next line without throwing any error, that means the library is set and ready to use. But if the output is similar to:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PSL'

that means the library did not install successfully or it did not install into the Python version using. Try double checking the Python versions and reinstall the pslab-python library following the instructions given in "Install PSLab Python Library"

πŸ“– Verify PSLab device connection with pslab-python library

This step requires a PSLab device. Try connecting your PSLab device with a USB cable and run the following Python statements in a Python console.

from PSL import sciencelab
I = sciencelab.connect()
print(I.get_capacitance())

If this program outputs a value similar to 9.1279170e-12, that means the device connection is successful. If it outputs something similar to:

Device not found. Programs already using : {'/dev/ttyACM0'}
Err
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/PSL/sciencelab.py", line 26, in connect
    raise RuntimeError('Could Not Connect')
RuntimeError: Could Not Connect

make sure that the device is connected and both the blue and green LEDs are lit.

Clone this wiki locally