How to import new packages

Hi
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/arbiter.py", line 473, in spawn_worker
    worker.init_process()
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 106, in wsgi
    self.callable = self.load()
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 27, in load
    return util.import_app(self.app_uri)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gunicorn/util.py", line 353, in import_app
    __import__(module)
  File "/edx/app/edxapp/edx-platform/lms/wsgi.py", line 27, in <module>
    startup.run()
  File "/edx/app/edxapp/edx-platform/lms/startup.py", line 19, in run
    django.setup()
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/apps/registry.py", line 116, in populate
    app_config.ready()
  File "/edx/app/edxapp/edx-platform/common/djangoapps/student/apps.py", line 20, in ready
    from .signals.receivers import update_last_login
  File "/edx/app/edxapp/edx-platform/common/djangoapps/student/signals/receivers.py", line 10, in <module>
    from student.helpers import (
  File "/edx/app/edxapp/edx-platform/common/djangoapps/student/helpers.py", line 10, in <module>
    import pyotp
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/pyotp/__init__.py", 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