translate / virtaal

Easy-to-use and powerful offline translation tool
https://virtaal.translatehouse.org
GNU General Public License v2.0
300 stars 58 forks source link

"bin/virtaal" imports old Virtaal package versions rather than the current source code #3245

Open yaoguai opened 8 years ago

yaoguai commented 8 years ago

I downloaded the latest beta version of Virtaal (1.0.0 beta 1). However, when I attempted to run "bin/virtaal" with Python 2.7 under Linux, the program immediately crashed and produced the following error:

Traceback (most recent call last):
  File "./bin/virtaal", line 43, in <module>
    'gtk':        'Gtk >= %s and PyGTK is required for Virtaal to function.' % str(depcheck.MIN_GTK_VERSION),
AttributeError: 'module' object has no attribute 'MIN_GTK_VERSION'

The reason is maybe not obvious at first glance, but the actual cause is that "bin/virtaal" has attempted to import the package "virtaal", but the import function will not search in the parent directory or the current working directory. It is searching several other directories including the "bin" directory where the "virtaal" executable is. It finds no "virtaal" package there, so it looks in the system packages, and finds the old Virtaal version: 0.7.1!

Even with perfectly new source code, the executable is still loading older versions of the program that are incompatible with it. This is potentially very dangerous for development, as you could be mixing executable and package versions! It is also bad for users who may either have the executable crash as a result of old and incompatible versions of Virtaal, or crash as a result of not having the "virtaal" package available in Python's import paths at all.

I think a shell script could be added for users who wish to run the program without first installing it as a Python package. Putting a shell script like this in the base directory would likely be helpful for end users:

run.sh

#!/bin/sh
cd $(dirname "$0") || exit 1
PYTHONPATH=. ./bin/virtaal
friedelwolff commented 8 years ago

I think we can document a trick like this, but in reality many python packages and programs require some kind of installation. Installing in a virtualenv should also work fine in this case, I believe.