holzschu / Carnets

Carnets is a stand-alone Jupyter notebook server and client. Edit your notebooks on the go, even where there is no network.
https://holzschu.github.io/Carnets_Jupyter/
BSD 3-Clause "New" or "Revised" License
567 stars 34 forks source link

Error importing piecash #138

Open ifuchs opened 3 years ago

ifuchs commented 3 years ago

Running the latest beta. I installed piecash (%pip install piecash) and when I try to import it, I get the following errors (this pure python module works in Pyto and Pythonista)

/var/mobile/Containers/Data/Application/CC437E91-94EE-46D7-8CF0-7BD4821F95B0/Library/lib/python3.9/site-packages/tzlocal/unix.py:158: UserWarning: Can not find any timezone configuration, defaulting to UTC. warnings.warn('Can not find any timezone configuration, defaulting to UTC.')

TypeError Traceback (most recent call last)

in ----> 1 import piecash /var/mobile/Containers/Data/Application/CC437E91-94EE-46D7-8CF0-7BD4821F95B0/Library/lib/python3.9/site-packages/piecash/__init__.py in --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in ----> 1 import piecash /var/mobile/Containers/Data/Application/CC437E91-94EE-46D7-8CF0-7BD4821F95B0/Library/lib/python3.9/site-packages/piecash/__init__.py in 13 Recurrence 14 ) ---> 15 from .core import ( 16 Book, 17 Account, ACCOUNT_TYPES, AccountType, /var/mobile/Containers/Data/Application/CC437E91-94EE-46D7-8CF0-7BD4821F95B0/Library/lib/python3.9/site-packages/piecash/core/__init__.py in ----> 1 from .session import create_book, open_book, Version 2 from .account import Account, ACCOUNT_TYPES, AccountType 3 from .book import Book 4 from .commodity import Commodity, Price 5 from .transaction import Transaction, Split, ScheduledTransaction, Lot /var/mobile/Containers/Data/Application/CC437E91-94EE-46D7-8CF0-7BD4821F95B0/Library/lib/python3.9/site-packages/piecash/core/session.py in 7 from sqlalchemy import event, Column, VARCHAR, INTEGER, Table, PrimaryKeyConstraint 8 from sqlalchemy.sql.ddl import DropConstraint, DropIndex ----> 9 from sqlalchemy_utils import database_exists 10 11 from piecash.core import factories /var/mobile/Containers/Data/Application/CC437E91-94EE-46D7-8CF0-7BD4821F95B0/Library/lib/python3.9/site-packages/sqlalchemy_utils/__init__.py in 47 ) 48 from .generic import generic_relationship # noqa ---> 49 from .i18n import TranslationHybrid # noqa 50 from .listeners import ( # noqa 51 auto_delete_orphans, /var/mobile/Containers/Data/Application/CC437E91-94EE-46D7-8CF0-7BD4821F95B0/Library/lib/python3.9/site-packages/sqlalchemy_utils/i18n.py in 11 try: 12 import babel ---> 13 import babel.dates 14 except ImportError: 15 babel = None /private/var/containers/Bundle/Application/FA397EF5-9E2D-410C-B7CE-EEFD13A6F40F/Carnets.app/Library/lib/python3.9/site-packages/babel/dates.py in 27 28 from babel.core import default_locale, get_global, Locale ---> 29 from babel.util import UTC, LOCALTZ 30 from babel._compat import string_types, integer_types, number_types, PY2 31 /private/var/containers/Bundle/Application/FA397EF5-9E2D-410C-B7CE-EEFD13A6F40F/Carnets.app/Library/lib/python3.9/site-packages/babel/util.py in 18 from babel._compat import izip, imap 19 import pytz as _pytz ---> 20 from babel import localtime 21 22 missing = object() /private/var/containers/Bundle/Application/FA397EF5-9E2D-410C-B7CE-EEFD13A6F40F/Carnets.app/Library/lib/python3.9/site-packages/babel/localtime/__init__.py in 72 73 try: ---> 74 LOCALTZ = get_localzone() 75 except pytz.UnknownTimeZoneError: 76 LOCALTZ = _FallbackLocalTimezone() /private/var/containers/Bundle/Application/FA397EF5-9E2D-410C-B7CE-EEFD13A6F40F/Carnets.app/Library/lib/python3.9/site-packages/babel/localtime/__init__.py in get_localzone() 68 better idea to use the :data:`LOCALTZ` singleton instead. 69 """ ---> 70 return _get_localzone() 71 72 /private/var/containers/Bundle/Application/FA397EF5-9E2D-410C-B7CE-EEFD13A6F40F/Carnets.app/Library/lib/python3.9/site-packages/babel/localtime/_unix.py in _get_localzone(_root) 72 sys_result = c.communicate()[0] 73 c.wait() ---> 74 tz_match = _systemconfig_tz.search(sys_result) 75 if tz_match is not None: 76 zone_name = tz_match.group(1) TypeError: cannot use a string pattern on a bytes-like object
holzschu commented 3 years ago

I see where the problem is: babel is trying to run an OSX command (systemsetup) because there is a test with if sys.platform == 'darwin': Since that command does not exist, it returns None, and that gives the result you had. I'll have to set the TZ environment variable to work around that.

In the meantime, you can probably apply the fix yourself, using !setenv TZ <whatever is applicable>