Installing python-eeml for python3


3 posts
by jbracegirdle » Fri Jul 20, 2012 10:49 pm
I'm trying to use my Raspberry Pi with an Arduino attached to update Cosm.
I started with this page: http://community.cosm.com/node/114
The code works will on python (version 2.7.3rc2) but I would like to try python3. I am very new to python and I'm not sure why python3 is better but having been released in 2008 it seems worth a try.

I've installed the prerequisites including lxml then ran python3 setup.py install this is the result:
Code: Select all
sudo apt-get install python3-lxml
...
pi@raspberrypi ~ $ git clone git://github.com/petervizi/python-eeml.git
Cloning into 'python-eeml'...
remote: Counting objects: 197, done.
remote: Compressing objects: 100% (131/131), done.
remote: Total 197 (delta 82), reused 160 (delta 50)
Receiving objects: 100% (197/197), 44.63 KiB, done.
Resolving deltas: 100% (82/82), done.
pi@raspberrypi ~ $ cd python-eeml/
pi@raspberrypi ~/python-eeml $ sudo python3 setup.py install
running install
Checking .pth file support in /usr/local/lib/python3.2/dist-packages/
/usr/bin/python3 -E -c pass
TEST PASSED: /usr/local/lib/python3.2/dist-packages/ appears to support .pth files
running bdist_egg
running egg_info
creating python_eeml.egg-info
writing requirements to python_eeml.egg-info/requires.txt
writing python_eeml.egg-info/PKG-INFO
writing top-level names to python_eeml.egg-info/top_level.txt
writing dependency_links to python_eeml.egg-info/dependency_links.txt
writing manifest file 'python_eeml.egg-info/SOURCES.txt'
reading manifest file 'python_eeml.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'python_eeml.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv6l/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/eeml
copying eeml/datastream.py -> build/lib/eeml
copying eeml/__init__.py -> build/lib/eeml
creating build/bdist.linux-armv6l
creating build/bdist.linux-armv6l/egg
creating build/bdist.linux-armv6l/egg/eeml
copying build/lib/eeml/datastream.py -> build/bdist.linux-armv6l/egg/eeml
copying build/lib/eeml/__init__.py -> build/bdist.linux-armv6l/egg/eeml
byte-compiling build/bdist.linux-armv6l/egg/eeml/datastream.py to datastream.cpython-32.pyc
byte-compiling build/bdist.linux-armv6l/egg/eeml/__init__.py to __init__.cpython-32.pyc
  File "build/bdist.linux-armv6l/egg/eeml/__init__.py", line 420
    Unit.__init__(self, 'Celsius', 'derivedSI', u'\xb0C')
                                                       ^
SyntaxError: invalid syntax

creating build/bdist.linux-armv6l/egg/EGG-INFO
copying python_eeml.egg-info/PKG-INFO -> build/bdist.linux-armv6l/egg/EGG-INFO
copying python_eeml.egg-info/SOURCES.txt -> build/bdist.linux-armv6l/egg/EGG-INFO
copying python_eeml.egg-info/dependency_links.txt -> build/bdist.linux-armv6l/egg/EGG-INFO
copying python_eeml.egg-info/not-zip-safe -> build/bdist.linux-armv6l/egg/EGG-INFO
copying python_eeml.egg-info/requires.txt -> build/bdist.linux-armv6l/egg/EGG-INFO
copying python_eeml.egg-info/top_level.txt -> build/bdist.linux-armv6l/egg/EGG-INFO
creating dist
creating 'dist/python_eeml-1.2.0-py3.2.egg' and adding 'build/bdist.linux-armv6l/egg' to it
removing 'build/bdist.linux-armv6l/egg' (and everything under it)
Processing python_eeml-1.2.0-py3.2.egg
removing '/usr/local/lib/python3.2/dist-packages/python_eeml-1.2.0-py3.2.egg' (and everything under it)
creating /usr/local/lib/python3.2/dist-packages/python_eeml-1.2.0-py3.2.egg
Extracting python_eeml-1.2.0-py3.2.egg to /usr/local/lib/python3.2/dist-packages
  File "/usr/local/lib/python3.2/dist-packages/python_eeml-1.2.0-py3.2.egg/eeml/__init__.py", line 420
    Unit.__init__(self, 'Celsius', 'derivedSI', u'\xb0C')
                                                       ^
SyntaxError: invalid syntax

python-eeml 1.2.0 is already the active version in easy-install.pth

Installed /usr/local/lib/python3.2/dist-packages/python_eeml-1.2.0-py3.2.egg
Processing dependencies for python-eeml==1.2.0
Searching for lxml==2.3.2
Best match: lxml 2.3.2
Adding lxml 2.3.2 to easy-install.pth file

Using /usr/lib/python3/dist-packages
Finished processing dependencies for python-eeml==1.2.0

The same process is working for python but not python3
When I try to run import eeml in python 3 I get:
Code: Select all
Python 3.2.3 (default, Jul  6 2012, 13:39:51)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import eeml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "eeml/__init__.py", line 420
    Unit.__init__(self, 'Celsius', 'derivedSI', u'\xb0C')
                                                       ^
SyntaxError: invalid syntax
>>>

I am using the new Raspbian wheezy image. I have done a search using Google and the forum search for "Unit.__init__(self, 'Celsius', 'derivedSI', u'\xb0C')" but I didn't find anything.
Thanks for any help or ideas.
Posts: 10
Joined: Sat Jul 14, 2012 7:45 pm
by timhoffman » Sat Jul 21, 2012 12:24 am
That eeml library hasn't been ported to python3.x. Python3.x dropped unicode prefix 'u' for unicode strings
.
ie
u'Some unicode String'
hence the error

Code: Select all
>>> import eeml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "eeml/__init__.py", line 420
    Unit.__init__(self, 'Celsius', 'derivedSI', u'\xb0C')
                                                                               ^
SyntaxError: invalid syntax
>>>


The prefixed 'u' in u'\xb0C' can be dropped and that particular statement would work. However this indicates there could be other problems in this code with regards to python3.x support. However it's probably worth a go ;-)

There is currently a PEP http://www.python.org/dev/peps/pep-0414/ to re-introduce this particular syntax in Python 3.3.
Posts: 85
Joined: Sat Nov 05, 2011 11:31 pm
by jbracegirdle » Sat Jul 21, 2012 10:52 am
Thanks for your help and advice. Just to update you on my progress.
I tried to convert the eeml package to Python3, but I think it may require more patience than I have for the task, I ran 2to3 that seemed to do not very much, changed ' ' to b' ' and used .decode() to get the text to print correctly, then I ran up against:
Code: Select all
Traceback (most recent call last):
  File "cosm-temp.py", line 17, in <module>
    pac = eeml.Pachube(API_URL, API_KEY)
  File "/usr/local/lib/python3.2/dist-packages/python_eeml-1.2.0-py3.2.egg/eeml/datastream.py", line 31, in __init__
    env = eeml.Environment()
NameError: global name 'eeml' is not defined

I think it's something to do with the way packages have changed but I'm not even sure Python3 will bring any advantages so I'm going to stick with Python.
From my introduction to Python it seems as though Python and Python3 are really different languages as they have incompatible libraries and 2to3 does not fix that many problems. I had an easier time converting the code from processing to Python (so it could run from the command line easily).
Posts: 10
Joined: Sat Jul 14, 2012 7:45 pm