Polyglot ImportError: cannot import name 'Locale' from 'icu' - polyglot

I was trying to run the polyglot for my sentimental analysis. After a lot of struggling,, I successfully installed Polyglot and pyicu. However when I ran my program, it gave me this error, and I don't know how to fix it
Traceback (most recent call last):
File "/Users/siyizhou/Documents/2020Fall/COMMresearch/code2/Pos_Neg.py", line 6, in <module>
from polyglot.text import Text
File "/usr/local/lib/python3.9/site-packages/polyglot/text.py", line 9, in <module>
from polyglot.detect import Detector, Language
File "/usr/local/lib/python3.9/site-packages/polyglot/detect/__init__.py", line 1, in <module>
from .base import Detector, Language
File "/usr/local/lib/python3.9/site-packages/polyglot/detect/base.py", line 11, in <module>
from icu import Locale
ImportError: cannot import name 'Locale' from 'icu' (/usr/local/lib/python3.9/site-
packages/icu/__init__.py)
siyizhou#Siyis-MBP code2 % polyglot download sentiment.en
Traceback (most recent call last):
File "/usr/local/bin/polyglot", line 33, in <module>
sys.exit(load_entry_point('polyglot==16.7.4', 'console_scripts', 'polyglot')())
File "/usr/local/bin/polyglot", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/local/Cellar/python#3.9/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/local/Cellar/python#3.9/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/usr/local/Cellar/python#3.9/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/polyglot/__main__.py", line 16, in <module> from icu import Locale
ImportError: cannot import name 'Locale' from 'icu' (/usr/local/Cellar/python#3.9/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/icu/__init__.py)

The problem is package dependency. Run the following commands in order:
1- pip3 install pyicu
2- pip3 install pycld2
3- pip3 install morfessor
That should work for your case. Also, for more detailed answers, check this link

If you are on MacOSX with a version around 13 (M1 or other), you may need some extra steps beforehand to update the search paths:
Start by installing pkg-config and icu4c, necessary for pyicu to work:
brew install pkg-config icu4c
Next, get the correct path to icu4c with the following command:
brew info icu4c
You will get an output like this:
==> icu4c: stable 71.1 (bottled) [keg-only] C/C++ and Java libraries for Unicode and globalization https://icu.unicode.org/home /opt/homebrew/Cellar/icu4c/71.1 (262 files, 76.8MB) Poured from bottle on 2023-01-02 at 16:21:11 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/icu4c.rb License: ICU
==> Caveats icu4c is keg-only, which means it was not symlinked into /opt/homebrew, because macOS provides libicucore.dylib (but nothing else).
If you need to have icu4c first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/icu4c/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/icu4c/sbin:$PATH"' >> ~/.zshrc
For compilers to find icu4c you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/icu4c/lib"
export CPPFLAGS="-I/opt/homebrew/opt/icu4c/include"
For pkg-config to find icu4c you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/icu4c/lib/pkgconfig"
==> Analytics install: 375,450 (30 days), 1,501,837 (90 days), 5,475,904 (365 days) install-on-request: 6,461 (30 days), 20,819 (90 days), 87,520 (365 days) build-error: 15 (30 days)
Look at the export sections, in this case, my path to icu4c is: /opt/homebrew/opt/icu4c/
Use this path you got to update the following commands:
export PATH="/opt/homebrew/opt/icu4c/bin:/opt/homebrew/opt/icu4c/sbin:$PATH"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/homebrew/opt/icu4c/lib/pkgconfig"
export PYICU_INCLUDES=/opt/homebrew/opt/icu4c/include
export PYICU_LFLAGS=-L/opt/homebrew/opt/icu4c/58.2/lib
You are now ready to follow the steps indicated by #Berkay 🤗
pip install pyicu
pip install morfessor
pip install pycld2

Related

Deploying 'Django for beginners' app to Heroku fails with ModuleNotFoundError: No module named '_tkinter'

I am following William Vincents Django for Beginners, and I'm about to push the blog app to Heroku at the end of chapter 8. I have checked the code several times, and everything is just as in the book, but it fails every time with ModuleNotFoundError: No module named '_tkinter'. Here is the log from Heroku:
-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
-----> Python app detected
-----> Using Python version specified in runtime.txt
! Python has released a security update! Please consider upgrading to python-3.10.4
Learn More: https://devcenter.heroku.com/articles/python-runtimes
-----> Installing python-3.10.3
-----> Installing pip 22.0.4, setuptools 60.10.0 and wheel 0.37.1
-----> Installing SQLite3
-----> Installing requirements with pip
Collecting asgiref==3.5.0
Downloading asgiref-3.5.0-py3-none-any.whl (22 kB)
Collecting Django==4.0.4
Downloading Django-4.0.4-py3-none-any.whl (8.0 MB)
Collecting gunicorn==20.1.0
Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
Collecting sqlparse==0.4.2
Downloading sqlparse-0.4.2-py3-none-any.whl (42 kB)
Collecting tzdata==2022.1
Downloading tzdata-2022.1-py2.py3-none-any.whl (339 kB)
Collecting whitenoise==5.3.0
Downloading whitenoise-5.3.0-py2.py3-none-any.whl (19 kB)
Installing collected packages: whitenoise, tzdata, sqlparse, gunicorn, asgiref, Django
Successfully installed Django-4.0.4 asgiref-3.5.0 gunicorn-20.1.0 sqlparse-0.4.2 tzdata-2022.1 whitenoise-5.3.0
-----> $ python manage.py collectstatic --noinput
Traceback (most recent call last):
File "/tmp/build_8fe73f22/manage.py", line 22, in <module>
main()
File "/tmp/build_8fe73f22/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 420, in execute
django.setup()
File "/app/.heroku/python/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.heroku/python/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/app/.heroku/python/lib/python3.10/site-packages/django/apps/config.py", line 304, in import_models
self.models_module = import_module(models_module_name)
File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/tmp/build_8fe73f22/blog/models.py", line 1, in <module>
from tkinter import CASCADE
File "/app/.heroku/python/lib/python3.10/tkinter/__init__.py", line 37, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
! Push rejected, failed to compile Python app.
! Push failed
The error shows that you have this in your blog/models.py:
from tkinter import CASCADE
That line certainly shouldn't be there. Tkinter is a graphical toolkit, and using it in any capacity in a Django project would be very unusual.
I suspect you are using an IDE that is "helpfully" guessing about missing imports and automatically adding them, probably because you typed CASCADE somewhere else in that file.
Remove that line (and any other imports you don't need, especially ones related to Tkinter), commit, and redeploy.

creating django project just doesnt work right

i create a project folder, than create a venv and do $ django-admin startproject trydjango.
now when i try to run runserver it gives me an error that it couldnt find manage.py, so i have to move it to the original project folder (which now has venv, trydjango, and manage.py). this is a problem i have seen online.
however, when i try to run runserver now it says:
"ModuleNotFoundError: No module named 'trydjango.settings'"
(full traceback below)
the weird thing is, i have opened a project file just like this before, but now its not working. i have done it in the exact same way, the exact way that tutorials show. the only thing that changed is the django version - the tutorial said to use 2.0.7 in order to be able to follow the tutorial.
full traceback:
Traceback (most recent call last):
File "E:\Python\projects\try_django_project\manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\core\management\__init__.py", line 317, in execute
settings.INSTALLED_APPS
File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__
self._setup(name)
File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\conf\__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "E:\Python\projects\try_django_project\venv\lib\site-packages\django\conf\__init__.py", line 106, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'trydjango.settings'
I will suggest you doing such way:
Create a virtualenvironment named env or venv or as your wish and activate it.
Then install django via pip install django
now run this command django-admin startproject trydjango You can
see you project structure such way:
-env
-trydjango
--trydjango
--manage.py
Now enter the project directory where manage.py stays and run python manage.py runserver
Hope this will work for you.

Django-widget-tweaks : ModuleNotFoundError: No module named 'widget_tweaks'

I am new to Django and also github CI/CD pipelines. I am working on a django project and I installed widget_tweaks via pip install django-widget-tweaks on the command prompt. The program and forms are working fine on the browser with no errors. However, I have a ci/cd pipeline on github to automate testing and when I try push the code, I get the following error:
Run pip3 install --user django
Collecting django
Downloading https://files.pythonhosted.org/packages/75/42/f59a8ebf14be6d17438f13042c775f53d3dfa71fff973e4aef64ca89582c/Django-3.1.6-py3-none-any.whl (7.8MB)
Collecting pytz (from django)
Downloading https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl (510kB)
Collecting sqlparse>=0.2.2 (from django)
Downloading https://files.pythonhosted.org/packages/14/05/6e8eb62ca685b10e34051a80d7ea94b7137369d8c0be5c3b9d9b6e3f5dae/sqlparse-0.4.1-py3-none-any.whl (42kB)
Collecting asgiref<4,>=3.2.10 (from django)
Downloading https://files.pythonhosted.org/packages/89/49/5531992efc62f9c6d08a7199dc31176c8c60f7b2548c6ef245f96f29d0d9/asgiref-3.3.1-py3-none-any.whl
Installing collected packages: pytz, sqlparse, asgiref, django
Successfully installed asgiref-3.3.1 django-3.1.6 pytz-2021.1 sqlparse-0.4.1
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/runner/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/runner/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/runner/.local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/runner/.local/lib/python3.6/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/runner/.local/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'widget_tweaks'
Error: Process completed with exit code 1.
My ci.yml file for the ci/cd pipeline looks like this:
name: Testing
on: push
jobs:
test_project:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Run Django unit tests
run: |
pip3 install --user django
python3 manage.py test
SOLVED: I added "pip3 install django-widget-tweaks" to the ci.yml file for the github CICD pipeline

How can i fix a GeoDjango OSError: undefined Symbol?

I have the following error with my Django project after doing yum upgrade a few days ago
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/home/joincic/GeoRouting/GeoRouting_2/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/db/models/options.py", line 204, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/home/joincic/GeoRouting/GeoRouting_2/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 6, in <module>
from .features import DatabaseFeatures
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/db/backends/postgis/features.py", line 1, in <module>
from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/db/backends/base/features.py", line 3, in <module>
from django.contrib.gis.db.models import aggregates
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
import django.contrib.gis.db.models.functions # NOQA
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/db/models/functions.py", line 4, in <module>
from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
from django.contrib.gis import forms, gdal
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
from .fields import ( # NOQA
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
from django.contrib.gis.gdal import GDALException
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/gdal/datasource.py", line 39, in <module>
from django.contrib.gis.gdal.driver import Driver
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "/home/joincic/GeoRouting/GeoRouting_2/lib/python3.6/site-packages/django/contrib/gis/gdal/libgdal.py", line 47, in <module>
lgdal = CDLL(lib_path)
File "/usr/lib64/python3.6/ctypes/__init__.py", line 343, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /usr/gdal30/lib/libgdal.so.26: undefined symbol: GEOSMakeValid_r
The project worked correctly before the upgrade, and trying to fix the error I installed gdal 3.0.2 but it didn't work
I don't know if you need more information about the project or about the virtual machine if so, you can ask me and I will gladly provide you any info
Any Ideas ?
I had the exact same problem with a customer and researched the cause. So while Iczub's answer is good, I think it worthwhile to explain the cause of the problem.
In my case, the error manifested like this:
test=> SELECT PostGIS_Full_Version();
ERROR: could not load library "/usr/pgsql-10/lib/rtpostgis-2.4.so": /usr/gdal30/lib/libgdal.so.26: undefined symbol: GEOSMakeValid_r
CONTEXT: SQL statement "SELECT public.postgis_gdal_version()"
PL/pgSQL function postgis_full_version() line 33 at SQL statement
The solution is simple:
# yum remove geos37
Explanation of what happened:
This was the consequence of a (minor) upgrade from postgis24_10-2.4.6-3.rhel7.x86_64 to postgis24_10-2.4.8-9.rhel7.x86_64 (repository pgdg10), which installed gdal30-libs-3.0.4 and geos38-3.8.1-1 as dependencies.
The ultimate cause of the problem is that the version of GEOS that was installed previously didn't get deinstalled:
# rpm -qa | grep geos
geos38-3.8.1-1.rhel7.x86_64
geos37-3.7.0-1.rhel7.x86_64
Now both of these packages have a library libgeos_c.so.1, installed in different directories:
/usr/geos38/lib64/libgeos_c.so.1
/usr/geos37/lib64/libgeos_c.so.1
Both packages put their directory in the shared library path by adding a configuration file to /etc/ld.so.conf.d, so we end up with two libraries of the same name on the path.
Unfortunately, the library from GEOS 3.7 happened to be the first one on the search path, so libgdal.so.26 loaded that one by mistake, which leads to the observed error.
Who is at fault?
I think there are two bugs:
The GEOS library libgeos_c has an ABI break between versions 3.7 and 3.8, but failed to change the library major version.
The PGDG RPM packages fail to implement an incompatibility between these two GEOS packages. They should never be installed at the same time.
In my case, yum had several enabled pgdg repositories and the gdal lib was installed from a different pg version as Postgis. After reducing the enabled pgdg repositories to just one (the version of interest) and reinstall ( or better erase & install) the effected packages, I was able to use pg with Postgis again.
How to disable repositories see How to enable or disable repositories in CentOS. Related file was in my case /etc/yum.repos.d/pgdg-redhat-all.repo
The mixed repository situation already exist before the upgrade and Postgis was working without trouble
[test#mytest ~]$ yum list installed | grep -i geos
geos37.x86_64 3.7.2-2.rhel7 #pgdg10
[test#mytest ~]$ yum list installed | grep -i gdal
gdal-libs.x86_64 1.11.4-12.rhel7 #pgdg96
gdal30-libs.x86_64 3.0.1-4.rhel7 #pgdg10
[test#mytest ~]$ yum list installed | grep -i postgis
postgis24_96.x86_64 2.4.8-5.rhel7 #pgdg96
postgis24_96-client.x86_64 2.4.8-5.rhel7 #pgdg96
[test#mytest ~]$ yum repolist enabled | grep -i Postgre
pgdg10/7/x86_64 PostgreSQL 10 for RHEL/CentOS 7 - x86_64 1,306
pgdg11/7/x86_64 PostgreSQL 11 for RHEL/CentOS 7 - x86_64 1,162
pgdg12/7/x86_64 PostgreSQL 12 for RHEL/CentOS 7 - x86_64 596
pgdg96/7/x86_64 PostgreSQL 9.6 for RHEL/CentOS 7 - x86_64 1,354
[test#mytest ~]$ psql
psql (9.6.15)
postgres=# CREATE DATABASE test;
CREATE DATABASE
postgres=# \connect test
You are now connected to database "test" as user "test".
test=# CREATE EXTENSION postgis;
CREATE EXTENSION
test=# \connect postgres
You are now connected to database "postgres" as user "test".
postgres=# DROP DATABASE test;
DROP DATABASE
After yum update the mixed repository situation was extended and postgis makes trouble. (grep search for pgdg to detect all effected packages)
[test#mytest ~]$ yum list installed | grep -i pgdg
CGAL.x86_64 4.7-1.rhel7.1 #pgdg11
SFCGAL.x86_64 1.3.1-2.rhel7 #pgdg12
SFCGAL-libs.x86_64 1.3.1-2.rhel7 #pgdg12
gdal-libs.x86_64 1.11.4-12.rhel7 #pgdg96
gdal30-libs.x86_64 3.0.1-4.rhel7 #pgdg10
geos37.x86_64 3.7.2-2.rhel7 #pgdg10
libgeotiff.x86_64 1.4.0-1.rhel7.1 #pgdg11
libgeotiff15.x86_64 1.5.1-2.rhel7 #pgdg12
ogdi.x86_64 3.2.0-4.rhel7.1 #pgdg11
ogdi41.x86_64 4.1.0-2.rhel7 #pgdg10
pgdg-redhat-repo.noarch 42.0-5 #pgdg10
postgis24_96.x86_64 2.4.8-5.rhel7 #pgdg96
...
proj62.x86_64 6.2.0-1.rhel7 #pgdg10
[test#mytest ~]$ psql
...
test=# CREATE EXTENSION postgis;
ERROR: could not load library "/usr/pgsql-9.6/lib/rtpostgis-2.4.so": /usr/gdal30/lib/libgdal.so.26: undefined symbol: GEOSMakeValid_r
test=#
I tried to reinstall Postgis with only only one pgpdg repository enabled. This was not reinstalling the dependent geos, gdal, proj packages. So I removed all effected packages and install them again.
[test#mytest ~]$ sudo yum erase CGAL geos37 proj62 proj49 ogdi41
[test#mytest ~]$ sudo yum install postgis24_96
[test#mytest ~]$ yum list installed | grep -i pgdg
CGAL.x86_64 4.7-1.rhel7 #pgdg96
SFCGAL.x86_64 1.3.1-1.rhel7 #pgdg96
SFCGAL-libs.x86_64 1.3.1-1.rhel7 #pgdg96
gdal30-libs.x86_64 3.0.4-2.rhel7 #pgdg96
geos38.x86_64 3.8.0-1.rhel7 #pgdg96
...
postgis24_96.x86_64 2.4.8-8.rhel7 #pgdg96
This is a hard system change, ensure to have a backup (e.g. VM snapshot). And also check, if dependent other installations (e.g. python shapely) still works with the changed libraries or requires a reinstall.

PyCharm: Cannot find Sphinx in selected interpreter

I am trying to create documentation using Sphinx in PyCharm and it does not work. I already tried using the terminal command make html and it seems to work just fine. When I try to run Sphinx task in PyCharm it raises this error:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/rest_runners/sphinx_runner.py", line 5, in <module>
from sphinx import cmdline
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/sphinx/cmdline.py", line 24, in <module>
from sphinx.application import Sphinx
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/sphinx/application.py", line 33, in <module>
from sphinx.environment import BuildEnvironment
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/sphinx/environment/__init__.py", line 45, in <module>
from sphinx.util.websupport import is_commentable
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/sphinx/util/websupport.py", line 11, in <module>
from sphinxcontrib.websupport.utils import is_commentable # NOQA
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/sphinxcontrib/websupport/__init__.py", line 13, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/setuptools-28.8.0-py3.6.egg/pkg_resources/__init__.py", line 3017, in <module>
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/setuptools-28.8.0-py3.6.egg/pkg_resources/__init__.py", line 3003, in _call_aside
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/setuptools-28.8.0-py3.6.egg/pkg_resources/__init__.py", line 3045, in _initialize_master_working_set
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/setuptools-28.8.0-py3.6.egg/pkg_resources/__init__.py", line 2577, in activate
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/setuptools-28.8.0-py3.6.egg/pkg_resources/__init__.py", line 2151, in declare_namespace
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/setuptools-28.8.0-py3.6.egg/pkg_resources/__init__.py", line 2091, in _handle_ns
File "/Users/wtekimam/PycharmProjects/doctor/myvenv/lib/python3.6/site-packages/setuptools-28.8.0-py3.6.egg/pkg_resources/__init__.py", line 2120, in _rebuild_mod_path
AttributeError: '_NamespacePath' object has no attribute 'sort'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/rest_runners/sphinx_runner.py", line 7, in <module>
raise NameError("Cannot find sphinx in selected interpreter.")
NameError: Cannot find sphinx in selected interpreter.
note: I use virtual environment and I already configure PyCharm to use the same virtual environment that I use to run make html in terminal
There are two requirements:
Install Sphinx into your project's interpreter.
Create a run configuration for a Sphinx task with the appropriate settings as specified in PyCharm's documentation.
Here's a typical configuration with screenshot.
Command: html
Input: path/to/reST/source/files
Output: path/to/reST/build/files
Python Interpreter: Project Default (or whatever you select)
Working directory: path/to/conf.py
The solution is to update all packages that are used in the interpreter.
In particular, update the setuptools package.
This worked for me, but I do not know why, I am sorry. None of the answers above helped.