Python GPSD Library Import Configuration - python

I'm working on a writing a Python script that will interface with and pull GPSD data into an application. This obviously involves an external library.
I have set up my configuration as follows on the Raspberry Pi I am using to deploy the code:
sudo apt-get install gpsd gpsd-clients python-gps
I have a working test sample code that creates the gps listener and pulls in data. It looks something like this:
gpsd = gps(mode=WATCH_ENABLE)
while gpsp.running:
gpsd.next()
It works great if I run it by calling the following command:
python test.py
But the code breaks due to an ImportError:
Traceback (most recent call last):
File "main.py", line 1, in <module>
from gps import *
ImportError: No module named gps
If I run it using:
python3 test.py
This makes sense to me because when I set up the project, I only included the libraries for the default Python (Python 2.7), not Python 3. But python3-gps isn't a package, and the rest of my project demands Python 3, so I don't know what to do.
Would it be possible to copy the Python 2.7 build of the gps library into Python 3 without errors? What other libraries should I look at? Is there anyway around this error?
Thanks so much!

There actually is a version make for version 3 -- see GitHub here...
https://github.com/tpoche/gps-python3
It advertises itself as a simple port to python 3....

The GPS3 project found on github is Python 2.7 to 3.4 compatible interface to the gpsd, yet doesn't import ancient cruft.
It is still alpha, but I would recommend it, at least for a poke and prod.

If you have pip3 installed use
pip3 install gps

Related

Trying to import python modules returns ModuleNotFound Error

Im attempting to use the numpy module in webots but whatever I try I always get
INFO: assignment_2_controller_2: Starting controller: python3.6 -u "assignment_2_controller_2.py"
[assignment_2_controller_2] Traceback (most recent call last):
[assignment_2_controller_2] File "assignment_2_controller_2.py", line 4, in <module>
[assignment_2_controller_2] import numpy
[assignment_2_controller_2] ModuleNotFoundError: No module named 'numpy'
WARNING: 'assignment_2_controller_2' controller exited with status: 1.
I have installed numpy with both pip2 and pip3 and neither seem to have made any difference and the package shows up in ~/.local/lib/python3.6/site-packages. I can also confirm that this module works in the python editor and in other python files.
Is there perhaps something I need to change in webots python Makefile or perhaps in my environment variables?
Edit:
Printing sys.path shows
'/snap/webots/14/usr/share/webots/lib/controller/python36', '/snap/webots/14/usr/lib/python36.zip', '/snap/webots/14/usr/lib/python3.6', '/snap/webots/14/usr/lib/python3.6/lib-dynload', '/snap/webots/14/usr/lib/python3/dist-packages'
I installed webots using snap but why wouldnt it use the python dictated by the PATH environment variable?
Fix:
By the looks of it snap creates a contained filesystem for webots to run in by design in which it installed its own python binaries. I therefore uninstalled webots with snap and then installed from the .deb file off their website and now it works fine.
Webots installed from the Snap package is running in a kind of sandbox, it is therefore using the version of Python distributed with the snap package (which you can't alter).
As explained in the documentation, you might use external controllers to launch yourself the controller instead of letting Webots starting it. This way you can chose which version of Python you want to use: https://cyberbotics.com/doc/guide/installation-procedure#installing-the-snap-package
Alternatively, you can use a different way to install Webots (from the Debian or archive package). The other installations are not coming with Python and are using the system Python.

Installing a python script in ImageJ

I’m trying to install a Python script in ImageJ. My preference is to use the script with ImageJ 1.x but can use Fiji if required. 
I am trying to use the script with ImageJ 1.x by placing it in the plugins folder.  The script appears in the plugins menu but when I try to run it I get an error that it can't find __future__
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named __future__
 
This makes no sense to me as the __future__ module is being used to import the with_statement module and python version is listed as :
2.5.4rc1 (2.5:723492dbab02, Feb 8 2013, 10:13:55)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)]
from __future__ import with_statement is specifically designed for use with Python versions 2.5.x
https://docs.python.org/3/library/future.html
So ... moving on ...
I tired to use Fiji instead since it is based on ImageJ2. 
I'm able to paste the code into the Script Editor using File > New > Script ...
The code runs when executed from there.  However, when saved I can't get it to show up in the plugins menu.  I've tried saving it to :
Fiji/plugins
Fiji/plugins/Scripts
Fiji/plugins/Scripts/Plugins
The file name has an _ in it.
The version of Fiji I'm running is
ImageJ 2.0.0 rc-68/1.52e / Java1.8.0_172 (64-bit)
The version of ImageJ 1.x I'm running is
ImageJ 1.52e / Java1.8.0_172 (64-bit)
Any help would be greatly appreciated.
Thanks
The canonical place to put scripts for ImageJ2 is scripts/Foo/Bar/My_Script.py, if you want it located in the menu at Foo > Bar > My Script.
It also works for backwards compatibility to use plugins or plugins/Scripts. However, there was recently a critical bug preventing scripts from appearing in the plugins-based locations; see this thread. The bug is fixed in the latest release.
you might want to have a look here on the ij-wiki. Also, there ij2 has its own, very active forum where this topic is also activeley discussed.
Best,
Felix

pygtk.glade 'no module named glade' on python 2.7

I am using Python 2.7 on windows
I want to install a software called febrl on python which requires pygtk.glade
I have installed all the modules that were specified in the software manual, especially PYGTK all-in-one but i get an error when i try to import pygtk.glade (i have no error when i do : import pygtk)
import pygtk.glade
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named glade
Is there a way to install glade for python on windows?
Thank you
maybe you need to do from pygtk import glade
check this for more information:
http://www.pygtk.org/articles/pygtk-glade-gui/Creating_a_GUI_using_PyGTK_and_Glade.htm
Gtk.Builder and friends are already in the Gtk module included. So, if you
from gi.repository import Gtk
you have access to the builder. You do not need Glade inside your python code. Glade is an external tool (separate from Python) which generates an XML file (normally called yourproject.ui, yourproject.glade or so), which is the description of the GUI you designed.
In your code you then have to make an instance of GtkBuilder, and read the XML file. This will generate all the widgets and make them available in your program.
Have a look at this tutorial.
That same XML is also usable in many other languages using a similar process - call GtkBuilder, etc.
Run this command below and it solve all your missing dependencies:
apt-get install python python-gtk2 python-glade2 libgtk2.0-dev libsqlite3-0
By running pip search glade I get this
BabelGladeExtractor (0.2dev-r288) - Babel Glade XML files translatable strings extractor
BD (0.0.5) - Bangladesh Details with postal code
GladeBuilder (0.1.0) - Easy way to get and set values/properties of
Gtk2/Gtk3 widgets.
SPE (0.8.3.c) - Python IDE with Blender, Kiki, PyChecker, Remote debugger, Uml and wxGlade support
I am pretty sure doing either
pip install GladeBuilder
of
pip install SPE
will solve it. But then again you are on windows so it really depends.

jython can't find 3rd party python package (python installed using miniconda)

I have a prototype written in Python that I need to port into Java to put into production. Python 2.7.10 has been installed using miniconda. The prototype uses a 3rd party library nltk that I installed using pip.
To void rewriting the code from scratch, at least initially, I want to first try call the prototype code directly from Java using jython.
When I try executing a command like
java -jar jython-standalone-2.7.0.jar myPrototype.py
I get
Traceback (most recent call last):
File "myPrototype.py", line 4, in <module>
from nltk import AlignedSent
ImportError: No module named nltk
It works fine when I run python myPrototype.py.
Is there a way of configuring my jython install so that it can find all 3rd party packages that I've added to my python install? I realize that some of those might not run in jython but at least I want to have access to those that do.
The bulk of NLTK is Python code so you should be able to use it from Jython as long as it's in your module search path. If you are on unix just add a link to your nltk in site-packages to the current folder. Or look into the documentation here: http://www.jython.org/jythonbook/en/1.0/ModulesPackages.html
NLTK needs to be able to load its data for some stuff. You may want to either make al link to your nltk_data from your home to the current folder or see this answer to set it from code: How to config nltk data directory from code?

How to install python database library to work with robotframework - API issue

I am on a Windows 7 64bit machine, using Python 2.7 and I am trying to use the python database library in robotframework. I have previously used a java library file but now I want to use the python library.
I have gone to github and downloaded version 0.6.
I have also installed a setup file and MySQL-python from here
However when I try to install the database library (using python setup.py build) I get the following error:
Traceback (most recent call last):
File "setup.py", line 25, in <module>
from DatabaseLibrary import __version__
File "src\DatabaseLibrary\__init__.py", line 15, in <module>
from connection_manager import ConnectionManager
File "src\DatabaseLibrary\connection_manager.py", line 16, in <module>
from robot.api import logger
ImportError: No module named api
Why do I not have robot.api and how do I get it and install it? Or is there an easier way to install the python database library?
It seems that the Database library uses Robot Framework internals, but does not list Robot Framework as it's dependency. The robot.api package was introduced in RF 2.6, so upgrading/installing the latest Robot Framework (from project pages) should resolve your issue
First ensure the integrity of your module before trying to install. In order to install a module using distutils (setup.py) you need to run this command as an administrator:
python setup.py install
That should run the setup and report back to you any missing dependencies.
Alternatively, you can install PIP from this location: PIP Project home page. Their page provides instructions how to install PIP, it's a package manager for Python, similar to PEAR for PHP, CPAN for Perl or gem for ruby. When you have it installed you can install packages with this command:
pip install <module>
The issue was I did not have the "API" folder in the "Robot" folder in "Python27\Lib\site-packages" as I did not have the latest version of RF. And logger is a new logging API for Robot Framework 2.6 since Oct 2011. (As janne as pointed out)
Two fixes for this issue seem to be:
Tested and worked but not recommended unless you dont want to update RF: Edit the 2 files "connection_manager.py" and "query.py" in "robotframework-databaselibrary-0.6" so that there is no dependency on the Robotframework logger. This is a easy and quick edit, where you replace the "from robot.api import logger" to "import logging" and "logger" to "logging"
See "http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html#programmatic-logging-apis" for more detail.
Reinstall Robotframework and ensure the "API" folder is created. This is recommended as it is the best approach.
(Added as an answer as too long for a comment)

Categories

Resources