miguelgrinberg / microblog

The microblogging application developed in my Flask Mega-Tutorial series. This version maps to the 2024 Edition of the tutorial.
http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
MIT License
4.55k stars 1.64k forks source link

Error with blocks #193

Closed ewandavis closed 4 years ago

ewandavis commented 4 years ago

I'm hitting an error in guess_language with blocks

File ".../microblog/venv/lib/python3.6/site-packages/guess_language/guess_language.py", line 37, in from blocks import unicodeBlock ImportError: cannot import name 'unicodeBlock'

I installed the latest stable version of blocks using the instruction here https://blocks.readthedocs.io/en/latest/setup.html

help("modules") shows block installed

Any pointers?

Thanks

Ewan

miguelgrinberg commented 4 years ago

I believe you are using an old version of the guess_language library that isn't Python 3 ready. That old version has a blocks.py module that collides with the blocks package of your IDE.

Can you share the output of pip freeze?

ewandavis commented 4 years ago

Thanks for your response: Here's pip freeze

(venv) ewan@oak:~/Dropbox/Python/microblog$ pip freeze alembic==1.3.1 Babel==2.7.0 blinker==1.4 blocks==0.2.0 certifi==2019.11.28 cffi==1.13.2 chardet==3.0.4 Click==7.0 cryptography==2.8 dominate==2.4.0 elasticsearch==7.1.0 Flask==1.1.1 Flask-Babel==0.12.2 Flask-Bootstrap==3.3.7.1 Flask-HTTPAuth==3.3.0 Flask-Login==0.4.1 Flask-Mail==0.9.1 Flask-Migrate==2.5.2 Flask-Moment==0.9.0 Flask-SQLAlchemy==2.4.1 Flask-WTF==0.14.2 fuel==0.2.0 guess-language==0.2 h5py==2.10.0 idna==2.8 itsdangerous==1.1.0 Jinja2==2.10.3 jwt==0.6.1 Mako==1.1.0 MarkupSafe==1.1.1 numexpr==2.7.0 numpy==1.9.3 picklable-itertools==0.1.1 Pillow==6.2.1 pkg-resources==0.0.0 progressbar2==3.6.0 pycparser==2.19 python-dateutil==2.8.1 python-dotenv==0.10.3 python-editor==1.0.4 pytz==2019.3 PyYAML==3.11 pyzmq==18.1.1 redis==3.3.11 requests==2.22.0 rq==1.1.0 scipy==1.3.3 six==1.9.0 SQLAlchemy==1.3.11 tables==3.6.1 Theano==0.8.0.dev0 toolz==0.7.2 urllib3==1.25.7 visitor==0.1.3 Werkzeug==0.16.0 WTForms==2.2.1

ewandavis commented 4 years ago

Looks like I have the latest version of guess-language Thanks Ewan

miguelgrinberg commented 4 years ago

The package is called guess_language_spirit. It is a newer version of the one you installed, which has been dead for many years.

ewandavis commented 4 years ago

Thanks, that,s fixed it .

Ewan

exowanderer commented 3 years ago

For anyone else who has the same problem that I did -- for which I don't know the cause -- here was my "solution".

I ran pip install guess_language-spirit; but when I import guess_language, I received the error ModuleNotFoundError: No module named 'blocks'.

I manually deleted all reference to guess_language from my conda env site-packages directory, and then re-installed it via pip install guess_language_spirit.

One of 2 things may have happened:

(1) I accidentally installed pip install guess_language-spirit (underscore then hyphen) -- should this be the same? (2) another package I was using installed pip install guess_language without me realizing it. Thus the cleaning removed versions that I did not realize were installed.

Either way, manually cleaning guess_language* from my env's site-packages directory and re-installing via pip worked for me.

marimeireles commented 1 year ago

This solution is not working on my linux:

Traceback (most recent call last):
  File "/home/myuser/miniconda3/envs/flask/lib/python3.10/site-packages/flask/cli.py", line 219, in locate_app
    __import__(module_name)
  File "/home/myuser/opendiscourse/commonsdialogue/commonsdialogue.py", line 1, in <module>
    from app import app
  File "/home/myuser/opendiscourse/commonsdialogue/app/__init__.py", line 21, in <module>
    from app import routes, models, errors
  File "/home/myuser/opendiscourse/commonsdialogue/app/routes.py", line 18, in <module>
    from guess_language import guess_language
  File "/home/myuser/miniconda3/envs/flask/lib/python3.10/site-packages/guess_language/guess_language.py", line 37, in <module>
    from blocks import unicodeBlock
ModuleNotFoundError: No module named 'blocks'

(flask) myuser@mypc [~/opendiscourse/commonsdialogue]#
(flask) myuser@mypc [~/opendiscourse/commonsdialogue]# which python
/home/myuser/miniconda3/envs/flask/bin/python
(flask) myuser@mypc [~/opendiscourse/commonsdialogue]# pip list | grep guess
guess-language        0.2
guess-language-spirit 0.5.3
miguelgrinberg commented 1 year ago

@marimeireles See current version of the Flask Mega-Tutorial on my blog, which uses a different library for language detection.