-
Notifications
You must be signed in to change notification settings - Fork 0
Install in Xubuntu 16.04

pslab-python library can be installed in a Xubuntu PC. This installation process mentioned here was tested on a computer running Xubuntu 16.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.
- π Dependencies and Pre-setup
- π Install PSLab Python library
- π Validate installation and Debug
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.
- Python 3.5 or above π
- Pip 19.0.3 or above π
- NumPy 1.16.3 or above π
- PySerial 3.4 or above π
- SetupTools 35.0.2 or above π
This step will guide you through setting up the correct Python version to run PSLab Python app
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;
$ python --versionThis should output something similar to:
Python 3.4.2If 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. But if the output is similar to something like:
Command 'python' not found, but can be installed with:
sudo apt install python3
sudo apt install python
sudo apt install python-minimal
You also have python3 installed, you can run 'python3' instead.Try the following command.
$ python3 --versionIf this command succeeds to output python version correctly and it is greater than 3.5, we can skip to the python path configuration section to get the previous command working without giving any errors.
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. Easiest is to use apt package manager. In the same terminal window, type the following command to update the package manager with latest software and install a copy of Python.
$ sudo apt-get update && sudo apt-get install python3.5 && sudo apt-get install python3.5-devThis will download and install Python 3.5 and it would take a few minutes to complete. Once that is done, we can configure Python path in system.
If you have multiple Python instances in your PC, you might need to revisit this section to switch between different Python versions. In this section, we are going to define Python paths in the system.
Find out the location where apt package manager has installed Python 3.5 resources. In the terminal window, type the following command to find out where the Python 3.5 directories are.
$ whereis python3.5Output of this command would look something similar to:
python3: /usr/bin/python3.4 /usr/bin/python3 /usr/bin/python3.4m-config /usr/bin/python3.5m /usr/bin/python3.5
/usr/bin/python3.4-config /usr/bin/python3.4m /etc/python3.4 /etc/python3 /etc/python3.5 /usr/lib/python3.4 /usr/lib
/python3 /usr/lib/python3.5 /usr/bin/X11/python3.4 /usr/bin/X11/python3 /usr/bin/X11/python3.4m-config /usr/bin
/X11/python3.5m /usr/bin/X11/python3.5 /usr/bin/X11/python3.4-config /usr/bin/X11/python3.4m /usr/local/lib/python3.4
/usr/local/lib/python3.5 /usr/include/python3.4 /usr/include/python3.4m /usr/share/python3 /usr/share/man/man1
/python3.1.gz
Look for a value similar to /usr/bin/python3.5. If it is there, we can proceed to the next stage. If there is no such path value in the result, make sure "Install Python 3" step didn't give any error.
Now in the terminal window, type the following command to add Python 3.5 as a new Python version to the system.
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 10This should not give any errors once executed. Next step is to configure the path. Type the following command in terminal:
$ sudo update-alternatives --config pythonDepending on the previous Python versions installed, it would output something similar to:
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.5 10 auto mode
1 /usr/bin/python3.4 5 manual mode
2 /usr/bin/python3.5 10 manual mode
Press enter to keep the current choice[*], or type selection number:Type the number related to /usr/bin/python3.5 and press Enter. Now try following commands once again to check whether the Python version is now set correctly.
$ python --version
Python 3.5.2
$ sudo python --version
Python 3.5.2
If both the versions are same and greater than 3.5, we have successfully completed step one installing and configuring Python 3..
This step will guide you through setting up Pip, a python package manager that is used in downloading and setting up other dependencies.
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-pipIt is good to upgrade the pip package before we finish up this step. Type the following command in terminal window.
$ python -m pip install --upgrade pipThis would exit with a result similar to an ending like:
Successfully installed pip-19.1.1With that being completed, next step is to install other dependency libraries.
This step will guide you through installing NumPy Python package.
Run the following command in terminal window to install NumPy from Python package manager.
$ sudo python -m pip install numpyIf 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
This step will guide you through installing PySerial Python package.
Run the following command in terminal window to install PySerial from Python package manager.
$ sudo python -m pip install pyserialIf 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.
This step will guide you through installing SetupTools Python package.
Run the following command in terminal window to install PySerial from Python package manager.
$ sudo python -m pip install setuptoolsIf 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 --upgradeThat's all the dependencies required by 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.
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.
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.gitThis will download the source code into a folder named pslab-python
If a user chose not to clone, but to download a release instead, do so by downloading the latest release in releases.
- π Version 1.0.1
- π Version 1.0.0
PSLab Python library uses a makefile to install the library in correct location.
If there are any corrupted PSLab library instances installed previously, run the following command in a terminal:
$ make fullcleanIt will throw many errors saying it cannot delete files if there are any. Because we are using a string matcher to find old components, go through the list to see if there are all inside a python folder.
...
rm: cannot remove '/usr/lib/python3/dist-packages/PSL_Apps/templates/__pycache__/graph_and_sheet.cpython-35.pyc': Permission denied
rm: cannot remove '/usr/lib/python3/dist-packages/PSL_Apps/templates/__pycache__/template_graph.cpython-35.pyc': Permission denied
rm: cannot remove '/usr/lib/python3/dist-packages/PSL_Apps/templates/__pycache__/ui_simpleTemplate.cpython-35.pyc': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/PSL/SENSORS/BH1750.pyc': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/PSL/packet_handler.pyc': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/PSL/commands_proto.py': Permission denied
rm: cannot remove '/usr/lib/python2.7/dist-packages/PSL/sciencelab.py': Permission denied
...
If you're certain that there are no other system files in it, execute the following command.
$ sudo make fullclean
Now run the following commands in sequence to complete the installation.
$ sudo make cleanThis will clean up the system to remove any previous pslab-python versions installed.
$ make allThis command will build the source code and prepare it for installation
$ sudo make installThis 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-pslabIf 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
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.
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:
$ pythonThis 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.1 (default, Oct 22 2018, 11:21:55)
[GCC 8.2.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"
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:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/PSL/sciencelab.py", line 30, 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.