abidinamdar / gmapcatcher

Automatically exported from code.google.com/p/gmapcatcher
1 stars 0 forks source link

Mac OS X - LookupError: unknown encoding - due to locale.getpreferredencoding() #353

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Am trying to create a redistributable app for Mac OS X. 

GMapCatcher runs pretty well with python2.7 installed via macports. However, 
creating an launcher app either with Automator or py2app results in the 
following error being reported to the Console Messages:

... File 
"/Users/cjreeve/Projects/GMapCatcher/gmapcatcher-test/gmapcatcher/mapConst.py", 
line 156, in <module>
... USER_Path = unicode(os.path.expanduser("~"), locale.getpreferredencoding())
... LookupError: unknown encoding: 

If I rename the line in mapsConst.py from
USER_Path = unicode(os.path.expanduser("~"), locale.getpreferredencoding())
to
USER_Path = "/Users/userID"

then I am able to create a linked app, which I run from the Dock. Do you know 
of any alternative ways of getting the path to the home directory that might 
work better?

Original issue reported on code.google.com by cjre...@gmail.com on 30 Oct 2012 at 9:14

GoogleCodeExporter commented 8 years ago
An unrelated issue, which has prevented me from creating a redistributable app 
using py2app, I get the following error:

File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/macholib/MachO.py", line 119, in write
    header.write(f)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/macholib/MachO.py", line 314, in write
    self.synchronize_size()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/macholib/MachO.py", line 304, in synchronize_size
    raise ValueError("New Mach-O header is too large to relocate")
ValueError: New Mach-O header is too large to relocate

Any ideas?

Original comment by cjre...@gmail.com on 30 Oct 2012 at 9:14

GoogleCodeExporter commented 8 years ago
I have no idea what is that "macholib" definitely not something that we use in 
GMapCatcher, maybe you can post the instructions to replicate the error

Original comment by heldersepu on 31 Oct 2012 at 12:40

GoogleCodeExporter commented 8 years ago
Ok, I would have posted the instructions anyway at some point to help people 
install GMapCatcher on the macs. It is rather long and drawn out and I might 
still not have the best way. I write the following as instructions so that it 
can be re-used, if needed, as User Installation instructions for mac users.

I think most people would prefer using python that comes bundled with their mac 
or at the worst, downloading the dmg from python's website. The problem with 
these installations is that they no longer come bundled with gobject, which 
seems to be used by GMapCatcher. Consequently, to install GMapCatcher, you need 
to know to be a little familiar with Bash and using Terminal - which is beyond 
most GUI folk.

Anyway, here is how I install and run GMapCatcher with MacPorts
---------------------------------------------------------------
- Make sure you have a copy of X11 installed and install it if not
- Download MacPorts from www.macports.org and follow installation instructions.
- When installed, it is probably helpful to update everything. However this can 
take many hours - you might need to leave your computer running over night. You 
can come back to these update instructions if you want to crack ahead. Enter 
the following into terminal (ignore the $'s):

$ sudo port -d selfupdate
$ sudo port upgrade outdated

If now or in the future macports is not able to finish an installation due to 
an error run the following command and try again:

$ sudo port clean --all

Now we will install python and gtk. Unfortunately, because I did not start with 
a clean install of MacPorts, I may have already had ports installed, so I do 
not know if this is the full list.

$ sudo port install python27
$ sudo port install py27-gtk
$ sudo port install py27-gobject  # this might be already installed

Now get a copy of GMapCatcher. I have problems with the current tar.gz 
available to download but you can get the latest development copy with svn, 
which you can install with MacPorts:

$ sudo port install subversion

# Download GMapCatcher to the folder GMapCatcher:
$ svn checkout http://gmapcatcher.googlecode.com/svn/trunk/ GMapCatcher

Check that X11 is running or is set up to start automatically and test if 
GMapCatcher runs

$ pythonw2.7 GMapCatcher/maps.py

If there is no maps.py there should be a 'mapcatcher' instead, which you should 
interchange in the above line.

If GMapCatcher fails to start due to some missing port you can find a suitable 
port by running the "port search phrase" command, where 'phrase' is what you 
are looking for. Then install the missing port(s) like the previous ports. To 
get GMapCatcher working with a GPS device, having installed the driver for your 
GPS device you you can do a "sudo port install gpsd" and run gpsd with 
something like "gpsd': gpsd -nN -D2 /dev/tty.usbserial". You can then also run 
"xgps" from the terminal to view all the satellites that have been found. Then 
start GMapCatcher, select GPSd in the GPS type and restart GMapCatcher. This 
should all be directly possible through the Serial option in GMapCatcher, but 
does not work for me - I haven't figured out why yet. However, to give 
GMapCatcher a chance to work in Serial mode, first install py27-serial:

$ sudo port install py27-serial

Create an aliased application  -- the Automator way
-----------------------------

Now GMapCatcher should be working nicely, apart from the fact that the only way 
to start it is via Terminal and typing in python2.7...etc To avoid that you can 
create a launcher/app for it. You can do this using the Automator, which is 
located in Utilities, and selecting "Run Shell Script" and entering the 
following into the text box: 
/opt/local/bin/pythonw2.7 
'/Users/YOURUSERNAME/GMapCatcher/gmapcatcher-test/maps.py'

Yes, you need the full paths to both python and maps.py. Save this as an app by 
going to File > Save As and then double click on the app in Finder or drag to 
your Dock. My only problem in using Automator is that it reports any errors as 
popups. Currently on my system I get the warning,
Xlib:  extension "RANDR" missing on display "/tmp/launch-H1ifLm/org.x:0"
which I have not been able to resolve by installing randr or/and the devel 
libraries.

The above app will also not currently run until you modify a GMapCatcher file, 
mapConst.py, which can be found in the folder gmapcatcher inside the main 
GMapCatcher directory. Scroll to the bottom and locate the following line,

USER_Path = unicode(os.path.expanduser("~"), locale.getpreferredencoding())

and replace this with 

USER_PATH = "/Users/YOURUSERNAME" 

Create an aliased application  -- the py2app way
-----------------------------

An alternative way to create the launcher, which does not report the RANDR 
error message and correctly sets the GMapCatcher icon, is using py2app, which 
can again be installed with with MacPorts. To install and then create the app 
using py2app enter the following,

$ sudo port install py27-py2app
$ cd GMapCatcher
$ py2applet-2.7 --make-setup maps.py
$ python2.7 setup.py py2app -A

After printing loads to screen it ends with,
*** creating application bundle: maps ***

Now, using Finder, browse to the GMapCatcher directory and open the newly 
created folder called "dist". There you should find a new application called 
maps.app. You can rename that, if you like, to GMapCather.app and copy or move 
it to your Applications. You can also drag it to your Dock. Note, that if X11 
is not set up to start automatically, GMapCatcher will still not run until you 
start X11.  

Console Errors
--------------

If you did not modify the mapConst.py file, as described above you will get a 
warning "maps Error", with the options to Terminate or Open Console. If you 
choose to open the Console it reports the following:

... import mapConst
... File 
"/Users/cjreeve/Projects/GMapCatcher/gmapcatcher-test/gmapcatcher/mapConst.py", 
line 156, in <module>
... USER_Path = unicode(os.path.expanduser("~"), locale.getpreferredencoding())
... LookupError: unknown encoding: 
... maps Error
... ([0x0-0x28e28e].org.pythonmac.unspecified.maps[48908]) Exited with exit 
code: 255

Building for deployment
-----------------------

The above methods of creating an app are linked to the GMapCatcher source code, 
which can't be moved once the app is created. It should be possible to bundle 
the whole source code into an app so that it can be offered as a download that 
can be simply unpacked into the Applications folder and run. I think it might 
be a matter of setting the correct compile options. Using just the basic 
instructions of removing the "build" and "dist" folders and running py2app 
without the -A option does not work:

$ rm -rf build dist          # remove build and dist folders
$ python2.7 setup.py py2app  # Build for deployment

...
File 
"/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-
packages/macholib/MachOStandalone.py", line 140, in run
    node.write(f)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/macholib/MachO.py", line 119, in write
    header.write(f)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/macholib/MachO.py", line 314, in write
    self.synchronize_size()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/macholib/MachO.py", line 304, in synchronize_size
    raise ValueError("New Mach-O header is too large to relocate")
ValueError: New Mach-O header is too large to relocate

Original comment by cjre...@gmail.com on 31 Oct 2012 at 1:18

GoogleCodeExporter commented 8 years ago
One step needs to update:

$ sudo port install py27-pygtk

Original comment by br...@geethree.com on 12 Feb 2014 at 2:05