redstreet / fava_investor

Comprehensive set of reports, analyses, and tools for investments, for Beancount and Fava (plain text, double entry accounting software). Includes Fava plugins, command line tools, and libraries for each module.
GNU General Public License v3.0
136 stars 20 forks source link

MacOS Install Problem? `Importing module "fava_investor" failed.` #55

Closed ChristopherA closed 3 years ago

ChristopherA commented 3 years ago

I'm trying to use beancount, fava and fava-investor.

I am using MacOS BigSur with all upgrades, and Safari.

I have installed brew, have done brew install fava which installs beancount and fava. I then did pip3 install fava-investor.

My beancount file is one known to be working with someone else, and it has the line:

2000-01-01 custom "fava-extension" "fava_investor" "{}"

However, when I fava my.beancount and open http://localhost:5000 I get in the Fava web interface under errors: Importing module "fava_investor" failed.

I'm not sure what I'm doing wrong, or how to diagnose the problem.

redstreet commented 3 years ago

What do you get if you open an interactive python3 shell and type: import fava_investor

ChristopherA commented 3 years ago

@redstreet, thank you for responding so quickly:

>>> import fava_investor
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/fava_investor/__init__.py", line 9, in <module>
    from .common.favainvestorapi import FavaInvestorAPI
  File "/usr/local/lib/python3.9/site-packages/fava_investor/common/favainvestorapi.py", line 2, in <module>
    from fava.template_filters import cost_or_value
  File "/usr/local/lib/python3.9/site-packages/fava/template_filters.py", line 21, in <module>
    from fava.context import g
  File "/usr/local/lib/python3.9/site-packages/fava/context.py", line 6, in <module>
    from fava.core import FavaLedger
  File "/usr/local/lib/python3.9/site-packages/fava/core/__init__.py", line 58, in <module>
    from fava.core.ingest import IngestModule
  File "/usr/local/lib/python3.9/site-packages/fava/core/ingest.py", line 12, in <module>
    from beancount.ingest import cache  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/beancount/ingest/cache.py", line 14, in <module>
    from beancount.utils import file_type
  File "/usr/local/lib/python3.9/site-packages/beancount/utils/file_type.py", line 22, in <module>
    import magic
  File "/usr/local/lib/python3.9/site-packages/magic/__init__.py", line 210, in <module>
    libmagic = loader.load_lib()
  File "/usr/local/lib/python3.9/site-packages/magic/loader.py", line 22, in load_lib
    glob.glob('/usr/local/Cellar/libmagic/*/lib/libmagic.dylib'),  # flake8:noqa
NameError: name 'glob' is not defined
>>>

When I did pip3 install fava-investor I didn't see any errors, but from this something seems installed incorrectly. Not a python dev so I have no idea how to diagnose.

ChristopherA commented 3 years ago

For reference, the install messages:

# pip3 install fava-investor
Requirement already satisfied: fava-investor in /usr/local/lib/python3.9/site-packages (0.2.1)
Requirement already satisfied: argh>=0.23.3 in /usr/local/lib/python3.9/site-packages (from fava-investor) (0.26.2)
Requirement already satisfied: beancount>=2.3.2 in /usr/local/lib/python3.9/site-packages (from fava-investor) (2.3.3)
Requirement already satisfied: argcomplete>=1.11.1 in /usr/local/lib/python3.9/site-packages (from fava-investor) (1.12.2)
Requirement already satisfied: tabulate>=0.8.3 in /usr/local/lib/python3.9/site-packages (from fava-investor) (0.8.7)
Requirement already satisfied: fava>=1.15 in /usr/local/lib/python3.9/site-packages (from fava-investor) (1.18)
Requirement already satisfied: pytest in /usr/local/lib/python3.9/site-packages (from beancount>=2.3.2->fava-investor) (6.2.2)
Requirement already satisfied: chardet in /usr/local/lib/python3.9/site-packages (from beancount>=2.3.2->fava-investor) (4.0.0)
Requirement already satisfied: bottle in /usr/local/lib/python3.9/site-packages (from beancount>=2.3.2->fava-investor) (0.12.19)
Requirement already satisfied: ply in /usr/local/lib/python3.9/site-packages (from beancount>=2.3.2->fava-investor) (3.11)
Requirement already satisfied: python-dateutil in /usr/local/lib/python3.9/site-packages (from beancount>=2.3.2->fava-investor) (2.8.1)
Requirement already satisfied: google-api-python-client in /usr/local/lib/python3.9/site-packages (from beancount>=2.3.2->fava-investor) (1.12.8)
Requirement already satisfied: python-magic in /usr/local/lib/python3.9/site-packages (from beancount>=2.3.2->fava-investor) (0.4.21)
Requirement already satisfied: requests in /usr/local/lib/python3.9/site-packages (from beancount>=2.3.2->fava-investor) (2.25.1)
Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.9/site-packages (from beancount>=2.3.2->fava-investor) (4.9.3)
Requirement already satisfied: lxml in /usr/local/lib/python3.9/site-packages (from beancount>=2.3.2->fava-investor) (4.6.2)
Requirement already satisfied: click in /usr/local/lib/python3.9/site-packages (from fava>=1.15->fava-investor) (7.1.2)
Requirement already satisfied: Flask-Babel>=1.0.0 in /usr/local/lib/python3.9/site-packages (from fava>=1.15->fava-investor) (2.0.0)
Requirement already satisfied: Werkzeug>=0.15.0 in /usr/local/lib/python3.9/site-packages (from fava>=1.15->fava-investor) (1.0.1)
Requirement already satisfied: Babel>=2.6.0 in /usr/local/lib/python3.9/site-packages (from fava>=1.15->fava-investor) (2.9.0)
Requirement already satisfied: markdown2>=2.3.0 in /usr/local/lib/python3.9/site-packages (from fava>=1.15->fava-investor) (2.4.0)
Requirement already satisfied: Jinja2>=2.10 in /usr/local/lib/python3.9/site-packages (from fava>=1.15->fava-investor) (2.11.3)
Requirement already satisfied: simplejson>=3.2.0 in /usr/local/lib/python3.9/site-packages (from fava>=1.15->fava-investor) (3.17.2)
Requirement already satisfied: cheroot in /usr/local/lib/python3.9/site-packages (from fava>=1.15->fava-investor) (8.5.2)
Requirement already satisfied: Flask>=0.10.1 in /usr/local/lib/python3.9/site-packages (from fava>=1.15->fava-investor) (1.1.2)
Requirement already satisfied: pytz>=2015.7 in /usr/local/lib/python3.9/site-packages (from Babel>=2.6.0->fava>=1.15->fava-investor) (2021.1)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.9/site-packages (from Flask>=0.10.1->fava>=1.15->fava-investor) (1.1.0)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.9/site-packages (from Jinja2>=2.10->fava>=1.15->fava-investor) (1.1.1)
Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.9/site-packages (from beautifulsoup4->beancount>=2.3.2->fava-investor) (2.2)
Requirement already satisfied: six>=1.11.0 in /usr/local/lib/python3.9/site-packages (from cheroot->fava>=1.15->fava-investor) (1.15.0)
Requirement already satisfied: more-itertools>=2.6 in /usr/local/lib/python3.9/site-packages (from cheroot->fava>=1.15->fava-investor) (8.7.0)
Requirement already satisfied: jaraco.functools in /usr/local/lib/python3.9/site-packages (from cheroot->fava>=1.15->fava-investor) (3.2.0)
Requirement already satisfied: google-api-core<2dev,>=1.21.0 in /usr/local/lib/python3.9/site-packages (from google-api-python-client->beancount>=2.3.2->fava-investor) (1.26.0)
Requirement already satisfied: google-auth-httplib2>=0.0.3 in /usr/local/lib/python3.9/site-packages (from google-api-python-client->beancount>=2.3.2->fava-investor) (0.0.4)
Requirement already satisfied: google-auth>=1.16.0 in /usr/local/lib/python3.9/site-packages (from google-api-python-client->beancount>=2.3.2->fava-investor) (1.26.1)
Requirement already satisfied: httplib2<1dev,>=0.15.0 in /usr/local/lib/python3.9/site-packages (from google-api-python-client->beancount>=2.3.2->fava-investor) (0.19.0)
Requirement already satisfied: uritemplate<4dev,>=3.0.0 in /usr/local/lib/python3.9/site-packages (from google-api-python-client->beancount>=2.3.2->fava-investor) (3.0.1)
Requirement already satisfied: protobuf>=3.12.0 in /usr/local/lib/python3.9/site-packages (from google-api-core<2dev,>=1.21.0->google-api-python-client->beancount>=2.3.2->fava-investor) (3.14.0)
Requirement already satisfied: packaging>=14.3 in /usr/local/lib/python3.9/site-packages (from google-api-core<2dev,>=1.21.0->google-api-python-client->beancount>=2.3.2->fava-investor) (20.9)
Requirement already satisfied: googleapis-common-protos<2.0dev,>=1.6.0 in /usr/local/lib/python3.9/site-packages (from google-api-core<2dev,>=1.21.0->google-api-python-client->beancount>=2.3.2->fava-investor) (1.52.0)
Requirement already satisfied: setuptools>=40.3.0 in /usr/local/lib/python3.9/site-packages (from google-api-core<2dev,>=1.21.0->google-api-python-client->beancount>=2.3.2->fava-investor) (53.0.0)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.9/site-packages (from google-auth>=1.16.0->google-api-python-client->beancount>=2.3.2->fava-investor) (0.2.8)
Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.9/site-packages (from google-auth>=1.16.0->google-api-python-client->beancount>=2.3.2->fava-investor) (4.7.1)
Requirement already satisfied: cachetools<5.0,>=2.0.0 in /usr/local/lib/python3.9/site-packages (from google-auth>=1.16.0->google-api-python-client->beancount>=2.3.2->fava-investor) (4.2.1)
Requirement already satisfied: pyparsing<3,>=2.4.2 in /usr/local/lib/python3.9/site-packages (from httplib2<1dev,>=0.15.0->google-api-python-client->beancount>=2.3.2->fava-investor) (2.4.7)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /usr/local/lib/python3.9/site-packages (from pyasn1-modules>=0.2.1->google-auth>=1.16.0->google-api-python-client->beancount>=2.3.2->fava-investor) (0.4.8)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.9/site-packages (from requests->beancount>=2.3.2->fava-investor) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/site-packages (from requests->beancount>=2.3.2->fava-investor) (2020.12.5)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/site-packages (from requests->beancount>=2.3.2->fava-investor) (1.26.3)
Requirement already satisfied: attrs>=19.2.0 in /usr/local/lib/python3.9/site-packages (from pytest->beancount>=2.3.2->fava-investor) (20.3.0)
Requirement already satisfied: pluggy<1.0.0a1,>=0.12 in /usr/local/lib/python3.9/site-packages (from pytest->beancount>=2.3.2->fava-investor) (0.13.1)
Requirement already satisfied: py>=1.8.2 in /usr/local/lib/python3.9/site-packages (from pytest->beancount>=2.3.2->fava-investor) (1.10.0)
Requirement already satisfied: toml in /usr/local/lib/python3.9/site-packages (from pytest->beancount>=2.3.2->fava-investor) (0.10.2)
Requirement already satisfied: iniconfig in /usr/local/lib/python3.9/site-packages (from pytest->beancount>=2.3.2->fava-investor) (1.1.1)
# 

Fava itself seems to be working.

redstreet commented 3 years ago

Sure. Try pip3 install glob

ChristopherA commented 3 years ago
# pip3 install glob
ERROR: Could not find a version that satisfies the requirement glob
ERROR: No matching distribution found for glob
 #

Ideas?

floatingheads commented 3 years ago

Try glob3 rather than glob.

ChristopherA commented 3 years ago

I've now tried:

# pip3 install glob3
ERROR: Could not find a version that satisfies the requirement glob3
ERROR: No matching distribution found for glob3
#

Same problem. Any thoughts?

floatingheads commented 3 years ago

If you try import glob does that work? glob should come pre-installed with python, so it's bizarre that it seems to be causing hiccups.

ChristopherA commented 3 years ago

This is a relatively fresh BigSur system and brew install, and as far as I know I'm not using any other python apps.

# python3
Python 3.9.2 (default, Feb 24 2021, 17:56:05) 
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import glob
>>> import fava_investor
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/fava_investor/__init__.py", line 9, in <module>
    from .common.favainvestorapi import FavaInvestorAPI
  File "/usr/local/lib/python3.9/site-packages/fava_investor/common/favainvestorapi.py", line 2, in <module>
    from fava.template_filters import cost_or_value
  File "/usr/local/lib/python3.9/site-packages/fava/template_filters.py", line 21, in <module>
    from fava.context import g
  File "/usr/local/lib/python3.9/site-packages/fava/context.py", line 6, in <module>
    from fava.core import FavaLedger
  File "/usr/local/lib/python3.9/site-packages/fava/core/__init__.py", line 58, in <module>
    from fava.core.ingest import IngestModule
  File "/usr/local/lib/python3.9/site-packages/fava/core/ingest.py", line 12, in <module>
    from beancount.ingest import cache  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/beancount/ingest/cache.py", line 14, in <module>
    from beancount.utils import file_type
  File "/usr/local/lib/python3.9/site-packages/beancount/utils/file_type.py", line 22, in <module>
    import magic
  File "/usr/local/lib/python3.9/site-packages/magic/__init__.py", line 210, in <module>
    libmagic = loader.load_lib()
  File "/usr/local/lib/python3.9/site-packages/magic/loader.py", line 22, in load_lib
    glob.glob('/usr/local/Cellar/libmagic/*/lib/libmagic.dylib'),  # flake8:noqa
NameError: name 'glob' is not defined
>>>
floatingheads commented 3 years ago

Does fava run for you? The code from fava_investor is just calling stuff from fava and Beancount, which in turn end up causing your error. It looks like the ingest module is causing the issue, which may be because it recently became gulp and got moved to a separate repo.

ChristopherA commented 3 years ago

Yes, fava runs, but it is what is displaying the error:

image
ChristopherA commented 3 years ago

I have also tried deleting python3 and reinstalling via brew, but that doesn't help:

# which python3
/usr/local/bin/python3
# rm -Rf /usr/local/bin/python3
/usr/local/bin/python3
# which python3
/usr/bin/python3
# rm -Rf /usr/bin/python3
rm: /usr/bin/python3: Operation not permitted
# brew install python3

I also tried it with the default python3 in BigSur that you now can't delete which is in /usr/bin/python3

# which python3
/usr/local/bin/python3
# /usr/local/bin/python3 --version
Python 3.9.2
# /usr/bin/python3 --version
Python 3.8.2
# 

-- Christopher Allen

redstreet commented 3 years ago

I'm unfortunately unable to repro your environment since I don't have a mac.

As @floatingheads pointed out, it's possible that if you install beangulp via pip, and then replace from beancount.ingest import with from beangulp import, you'll hit a more well tested code path.

ChristopherA commented 3 years ago

Note that if I pip3 install beancount fava fave-investor on a fresh Big Sur installation (which finally includes Python 3), fava-investor works. If I install using brew brew install beancount fava and then pip3 install fave-investor it doesn't work.

redstreet commented 3 years ago

Glad you were able to get it to work. Thanks for reporting back, @ChristopherA! I've added a note in the README.md linking to this ticket.