How to import new packages

how to import new packages to open edx ?
for example this library pyotp?

I tried this command

sudo pip install --target=/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/ pyotp

but I faced this error

Traceback (most recent call last):
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gunicorn/", line 473, in spawn_worker
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gunicorn/workers/", line 100, in init_process
    self.wsgi =
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gunicorn/app/", line 106, in wsgi
    self.callable = self.load()
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gunicorn/app/", line 27, in load
    return util.import_app(self.app_uri)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gunicorn/", line 353, in import_app
  File "/edx/app/edxapp/edx-platform/lms/", line 27, in <module>
  File "/edx/app/edxapp/edx-platform/lms/", line 19, in run
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/", line 27, in setup
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/apps/", line 116, in populate
  File "/edx/app/edxapp/edx-platform/common/djangoapps/student/", line 20, in ready
    from .signals.receivers import update_last_login
  File "/edx/app/edxapp/edx-platform/common/djangoapps/student/signals/", line 10, in <module>
    from student.helpers import (
  File "/edx/app/edxapp/edx-platform/common/djangoapps/student/", line 10, in <module>
    import pyotp
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/pyotp/", line 12
    def random_base32(length: int = 32, chars: Sequence[str] = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')) -> str:
SyntaxError: invalid syntax

@muneera_salah, it looks like you are trying to use a Python 3 package with Python 2.7. pyotp is not supported for Python 2.7 after v2.3.0 (ref).

Also, instead of using the --target option, you can use /edx/app/edxapp/venvs/edxapp/bin/pip to install the package in the proper virtual environment.

1 Like

@Agrendalath many thanks, appreciate your support