No module named 'backports' - python

I am trying to build a python project using 'make build' command but getting below error while doing that. It was working earlier but starting throwing this error recently.
Collecting backports.zoneinfo (from -r requirements.txt (line 4))
Downloading https://<ARTIFACTORY_URL>/artifactory/api/pypi/pypi-release/packages/packages/ad/85/475e514c3140937cf435954f78dedea1861aeab7662d11de232bdaa90655/backports.zoneinfo-0.2.1.tar.gz (74kB)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-dcqnjb0t/backports.zoneinfo/setup.py", line 26, in <module>
setuptools.setup(ext_modules=[c_extension])
File "/usr/src/venv/lib/python3.6/site-packages/setuptools/__init__.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.6/distutils/core.py", line 121, in setup
dist.parse_config_files()
File "/usr/src/venv/lib/python3.6/site-packages/setuptools/dist.py", line 494, in parse_config_files
ignore_option_errors=ignore_option_errors)
File "/usr/src/venv/lib/python3.6/site-packages/setuptools/config.py", line 106, in parse_configuration
meta.parse()
File "/usr/src/venv/lib/python3.6/site-packages/setuptools/config.py", line 382, in parse
section_parser_method(section_options)
File "/usr/src/venv/lib/python3.6/site-packages/setuptools/config.py", line 355, in parse_section
self[name] = value
File "/usr/src/venv/lib/python3.6/site-packages/setuptools/config.py", line 173, in __setitem__
value = parser(value)
File "/usr/src/venv/lib/python3.6/site-packages/setuptools/config.py", line 430, in _parse_version
version = self._parse_attr(value)
File "/usr/src/venv/lib/python3.6/site-packages/setuptools/config.py", line 305, in _parse_attr
module = import_module(module_name)
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 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
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 'backports'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-dcqnjb0t/backports.zoneinfo/
You are using pip version 9.0.1, however version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The package is downloaded when clicked on the artifactory link directly.
I tried installing the package separately using
pip install backports-zoneinfo
but still getting the same issue. The python version of venv is Python 3.8.8
Here is the requirements file:
gunicorn==19.9.0
MarkupSafe==1.1.1
backports.zoneinfo
flask
flake8
blinker==1.4
marshmallow==2.13.5
flasgger==0.9.2
pytest
firewall==1.1
sftpip==1.1
python-json-logger
pytest-cov
hvac
apscheduler
cryptography==2.2.2
pip list:
Package Version
------------------ ----------
appdirs 1.4.4
APScheduler 3.7.0
asn1crypto 1.4.0
attrs 20.3.0
backports.weakref 1.0.post1
backports.zoneinfo 0.2.1
.....

I did not manage to get this working, so I upgraded to python3.9. There import zoneinfo is enough...

Related

AioHttp Installation: multidict module error

I tried installing the AioHttp package, as seen in the extract below. The installation failed with the multidict module.
root#ava:/home/cliquant/server/ava# pip3 install aiohttp
Collecting aiohttp
Using cached https://files.pythonhosted.org/packages/ff/4f/62d9859b7d4e6dc32feda67815c5f5ab4421e6909e48cbc970b6a40d60b7/aiohttp-3.8.3.tar.gz
Complete output from command python setup.py egg_info:
*********************
* Accelerated build *
*********************
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-0b29nbfp/aiohttp/setup.py", line 54, in <module>
setup(**setup_kwargs)
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.6/distutils/core.py", line 121, in setup
dist.parse_config_files()
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 494, in parse_config_files
ignore_option_errors=ignore_option_errors)
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 106, in parse_configuration
meta.parse()
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 382, in parse
section_parser_method(section_options)
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 355, in parse_section
self[name] = value
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 173, in __setitem__
value = parser(value)
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 430, in _parse_version
version = self._parse_attr(value)
File "/usr/lib/python3/dist-packages/setuptools/config.py", line 305, in _parse_attr
module = import_module(module_name)
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 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 "/tmp/pip-build-0b29nbfp/aiohttp/aiohttp/__init__.py", line 5, in <module>
from . import hdrs as hdrs
File "/tmp/pip-build-0b29nbfp/aiohttp/aiohttp/hdrs.py", line 8, in <module>
from multidict import istr
ModuleNotFoundError: No module named 'multidict'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-0b29nbfp/aiohttp/`
I got error when installing aiohttp with pip3.
How can I fix this?
NB: I can't find in google about it...
Google came to your aid narrowing down on the ModuleNotFoundError: No module named 'multidict'
To resolve, install the multidict module.
python3 -m pip install multidict or
pip3 install multidict
See this GitHub issue #277, and
this SO question
[Edit] For completeness, ensure you are installing in the correct environment env.
Also, check the version(s) of python installed on the system.

I install tensorflow using pip but tensorflow import does not work

I have installed tensorflow like so: pip3.8 install tensorflow (I am using pip3.8 command as I have several python versions installed on my EC2 instance). When I do so I get this output:
Defaulting to user installation because normal site-packages is not writeable
Collecting tensorflow
Downloading tensorflow-2.8.0-cp38-cp38-manylinux2010_x86_64.whl (497.6 MB)
|████████████████████████████████| 497.6 MB 37.1 MB/s eta 0:00:01Killed
Everytime I install I get the same output. I have a django project that is working just fine on my local machine but when I test it with python3.8 manage.py runserver --insecure on the EC2 instance:
Performing system checks...
Failed to import tensorflow. Please note that tensorflow is not installed by default when you install tensorflow_hub. This is so that users can decide which tensorflow package to use. To use tensorflow_hub, please install a current version of tensorflow by following the instructions at https://tensorflow.org/install and https://tensorflow.org/hub/installation.
Failed to import tensorflow. Please note that tensorflow is not installed by default when you install tensorflow_hub. This is so that users can decide which tensorflow package to use. To use tensorflow_hub, please install a current version of tensorflow by following the instructions at https://tensorflow.org/install and https://tensorflow.org/hub/installation.
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/core/management/base.py", line 419, in check
all_issues = checks.run_checks(
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/core/checks/registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/urls/resolvers.py", line 412, in check
for pattern in self.url_patterns:
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/urls/resolvers.py", line 598, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/urls/resolvers.py", line 591, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/ec2-user/Style-transfer-app/websrc/styletransferapp/urls.py", line 23, in <module>
path('', include('mainpage.urls')),
File "/home/ec2-user/.local/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/ec2-user/Style-transfer-app/websrc/mainpage/urls.py", line 2, in <module>
from . import views
File "/home/ec2-user/Style-transfer-app/websrc/mainpage/views.py", line 3, in <module>
import tensorflow_hub as hub
File "/home/ec2-user/.local/lib/python3.8/site-packages/tensorflow_hub/__init__.py", line 85, in <module>
_ensure_tf_install()
File "/home/ec2-user/.local/lib/python3.8/site-packages/tensorflow_hub/__init__.py", line 49, in _ensure_tf_install
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
When I run pip3.8 freeze after trying pip3.8 install tensorflow several times I get:
asgiref==3.5.0
Django==3.2.5
numpy==1.22.2
protobuf==3.19.4
pytz==2021.3
sqlparse==0.4.2
tensorflow-hub==0.12.0
When I run pip3.8 --version I get:
pip 21.1.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
I have also tried sudo pip3.8 install tensorflow which has given the same output as when I run the same command without sudo.
I am using python 3.8.12 (I have installed it manually from source).
Does anyone know how I can fix this?

Issue with installing Flask-Migrate

I have been trying to get Flask-Migrate to install it just doesn't want to work. Someone help me out please. I have tried to uninstall pip but that still doesnt work for me. I really dont understand what im doing wrong.
python3 -m pip install Flask-Migrate
Collecting Flask-Migrate
Using cached Flask_Migrate-2.5.3-py2.py3-none-any.whl (13 kB)
Collecting Flask-SQLAlchemy>=1.0
Using cached Flask_SQLAlchemy-2.4.1-py2.py3-none-any.whl (17 kB)
Requirement already satisfied: Flask>=0.9 in /Library/Python/3.7/site-packages (from Flask-Migrate) (1.1.1)
Collecting alembic>=0.7
Using cached alembic-1.4.2.tar.gz (1.1 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
ERROR: Exception:
Traceback (most recent call last):
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_internal/cli/base_command.py", line 186, in _main
status = self.run(options, args)
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_internal/commands/install.py", line 331, in run
resolver.resolve(requirement_set)
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_internal/legacy_resolve.py", line 177, in resolve
discovered_reqs.extend(self._resolve_one(requirement_set, req))
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_internal/legacy_resolve.py", line 333, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_internal/legacy_resolve.py", line 282, in _get_abstract_dist_for
abstract_dist = self.preparer.prepare_linked_requirement(req)
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_internal/operations/prepare.py", line 516, in prepare_linked_requirement
req, self.req_tracker, self.finder, self.build_isolation,
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_internal/operations/prepare.py", line 95, in _get_prepared_distribution
abstract_dist.prepare_distribution_metadata(finder, build_isolation)
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_internal/distributions/sdist.py", line 38, in prepare_distribution_metadata
self._setup_isolation(finder)
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_internal/distributions/sdist.py", line 96, in _setup_isolation
reqs = backend.get_requires_for_build_wheel()
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_vendor/pep517/wrappers.py", line 152, in get_requires_for_build_wheel
'config_settings': config_settings
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_vendor/pep517/wrappers.py", line 255, in _call_hook
raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pep517.wrappers.BackendUnavailable: Traceback (most recent call last):
File "/Users/sai/Library/Python/3.7/lib/python/site-packages/pip/_vendor/pep517/_in_process.py", line 63, in _build_backend
obj = import_module(mod_path)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'setuptools'

How to fix ImportError "_psutil_linux" on Heroku

I need psutil in my code but I get the error "importError _psutil_linux" on Heroku
it's for a status application on the use of the system and what's left of free.
I've already tried:
- to force the installation with pip (not work)
- to change the version with the file requirements.txt (not work)
requirements.txt :
Unidecode==1.0.22
youtube_dl==2018.7.21
chardet==3.0.4
urlextract==0.8.3
feedparser==5.2.1
requests==2.18.4
setuptools==40.2.0
aiohttp==1.0.5
urllib3==1.22
discord.py==0.16.12
psutil==5.4.7
pip==9.0.3
pyparsing==2.2.0
Pillow==5.3.0
beautifulsoup4==4.6.3
httplib2==0.11.3
imgurpython==1.1.7
keyboard==0.13.2
google_api_python_client==1.7.4
pyfiglet==0.7.5
pylast==2.4.0
r6sapi==0.8.0
raven==6.9.0
raven_aiohttp==0.7.0
tabulate==0.8.2
typing==3.6.6
my use of psutil :
import psutil
CPU = psutil.cpu_percent()
RAM =psutil.virtual_memory().percent
(in a discord bot command.)
Traceback (most recent call last):
File "/app/cogs/owner.py", line 65, in load
self._load_cog(module)
File "/app/cogs/owner.py", line 946, in _load_cog
mod_obj = importlib.import_module(cogname)
File "/app/.heroku/python/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 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 "/app/cogs/cyvgeneral.py", line 7, in <module>
import psutil
File "lib/psutil/__init__.py", line 100, in <module>
from . import _pslinux as _psplatform
File "lib/psutil/_pslinux.py", line 26, in <module>
from . import _psutil_linux as cext
ImportError: cannot import name '_psutil_linux'
I expect Psutil to load correctly.
thank you in advance.

Trying to install python-social-auth, get ImportError: No module named 'requests.packages'

Question title says it all. I'm not a Python expert, not sure where to go from here. I tried everything I could think of.
I'm using pip3 and python3 with Django 1.8.
Following instructions from https://github.com/omab/python-social-auth I did sudo pip3 install python-social-auth and all the dependencies.
Shell output:
$ python3 manage.py shell
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python3.4/dist-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/usr/local/lib/python3.4/dist-packages/social/apps/django_app/default/models.py", line 8, in <module>
from social.utils import setting_name
File "/usr/local/lib/python3.4/dist-packages/social/utils.py", line 13, in <module>
from requests.packages.urllib3.poolmanager import PoolManager
ImportError: No module named 'requests.packages'
I'm not sure why the python-social-auth module tries to call requests.packages since that does not seem to exist in the "requests" module.
I solved my own problem.
sudo pip3 install requests --upgrade
Fixed it by upgrading my system's "requests" package.
this question may be getting a bunch of new visitors...
requests.packages has been removed from requests:
https://github.com/kennethreitz/requests/pull/4067
install the vendored libraries separately
pip install urllib3

Categories