ImportError: No module named pytz

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

xxx@hostname:/opt/xx/cc$ python manage.py runserver 0.0.0.0:8814
Traceback (most recent call last):
  File "manage.py", line 9, in <module>
    from django.core.management import execute_from_command_line
  File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/core/management/__init__.py", line 13, in <module>
    from django.core.management.base import (
  File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/core/management/base.py", line 17, in <module>
    from django.db.migrations.exceptions import MigrationSchemaMissing
  File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/db/migrations/__init__.py", line 2, in <module>
    from .operations import *  # NOQA
  File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/db/migrations/operations/__init__.py", line 1, in <module>
    from .fields import AddField, AlterField, RemoveField, RenameField
  File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/db/migrations/operations/fields.py", line 4, in <module>
    from django.db.models.fields import NOT_PROVIDED
  File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/db/models/__init__.py", line 3, in <module>
    from django.db.models.aggregates import *  # NOQA
  File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/db/models/aggregates.py", line 5, in <module>
    from django.db.models.expressions import Func, Star
  File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/db/models/expressions.py", line 5, in <module>
    from django.db.backends import utils as backend_utils
  File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/db/backends/utils.py", line 12, in <module>
    from django.utils.timezone import utc
  File "/usr/local/lib/python2.7/dist-packages/Django-1.11.3-py2.7.egg/django/utils/timezone.py", line 8, in <module>
    import pytz
ImportError: No module named pytz

Installation

pip install pytz

Report error again

xxx@hostname:/opt/xx/cc$ pip install pytz
Downloading/unpacking pytz
  Downloading pytz-2019.1-py2.py3-none-any.whl (510kB): 510kB downloaded
Installing collected packages: pytz
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1436, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 672, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 902, in move_wheel_files
    pycompile=self.pycompile,
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 206, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 193, in clobber
    os.makedirs(destsubdir)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pytz-2019.1.dist-info'

Storing debug log for failure in /tmp/tmpbGaHeV

Use sudo permission

sudo pip install pytz

Installation successful

xxx@hostname:/opt/xx/cc$ sudo pip install pytz
Downloading/unpacking pytz
  Downloading pytz-2019.1-py2.py3-none-any.whl (510kB): 510kB downloaded
Installing collected packages: pytz
Successfully installed pytz
Cleaning up...
xxx@hostname:/opt/xx/cc$

Reference:

https://blog.csdn.net/qq_38157974/article/details/78521088

Similar Posts: