title: ModuleNotFoundError: No module named 'rest_framework'. How can I fix this error?
body: <p>I am new to Django. I am using Ubuntu, Apache, and virtualenv. I am running Ubuntu on DigitalOcean. I am trying to use Django and React together. So I downloaded djangorestframework. But when I run the server, I encountered this problem.</p>
  
  <pre><code>(new_app) sot232@ubuntu:/var/www/html/django_app/commercial$ python3 manage.py runserver
  Watching for file changes with StatReloader
  Exception in thread django-main-thread:
  Traceback (most recent call last):
    File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
      self.run()
    File "/usr/lib/python3.7/threading.py", line 865, in run
      self._target(*self._args, **self._kwargs)
    File "/home/sot232/new_app/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
      fn(*args, **kwargs)
    File "/home/sot232/new_app/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
      autoreload.raise_last_exception()
    File "/home/sot232/new_app/lib/python3.7/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
      raise _exception[0](_exception[1]).with_traceback(_exception[2])
    File "/home/sot232/new_app/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
      fn(*args, **kwargs)
    File "/home/sot232/new_app/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
      apps.populate(settings.INSTALLED_APPS)
    File "/home/sot232/new_app/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
      app_config = AppConfig.create(entry)
    File "/home/sot232/new_app/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
      module = import_module(entry)
    File "/home/sot232/new_app/lib/python3.7/importlib/__init__.py", line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "&lt;frozen importlib._bootstrap&gt;", line 1006, in _gcd_import
    File "&lt;frozen importlib._bootstrap&gt;", line 983, in _find_and_load
    File "&lt;frozen importlib._bootstrap&gt;", line 965, in _find_and_load_unlocked
  ModuleNotFoundError: No module named 'rest_framework'
  </code></pre>
  
  <p>I included rest_framework properly in the settings.py file.</p>
  
  <pre><code>INSTALLED_APPS = [
      'rest_framework',
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'commercial',
  ]
  </code></pre>
  
  <p>I tried these commands.</p>
  
  <pre><code>sudo pip3 install djangorestframework
  sudo pip install djangorestframework
  sudo pip install django-rest-swagger
  sudo apt-get install python3-setuptools
  </code></pre>
  
  <p>I also tried to install djangorestframework after <code>sudo su</code>.</p>
  
  <p>(I tried other suggestions too. But I can't remember those.)</p>
  
  <p>In addition, here's what I got on a python shell.</p>
  
  <pre><code>Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
  [GCC 8.3.0] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import rest_framework
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  ModuleNotFoundError: No module named 'rest_framework'
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>Here is a dist-packages in case you need it.</p>
  
  <pre><code>(new_app) sot232@ubuntu:/usr/local/lib/python3.7/dist-packages$ ls
  Django-2.2.1.dist-info               pytz-2019.1.dist-info
  __pycache__                          rest_framework
  corsheaders                          sqlparse
  django                               sqlparse-0.3.0.dist-info
  django_cors_headers-3.0.0.dist-info  virtualenv-16.5.0.dist-info
  djangorestframework-3.9.4.dist-info  virtualenv.py
  pytz                                 virtualenv_support
  </code></pre>
  
  <p>How can I fix my problem?</p>
  
  <p>Any help will be appreciated. I saw other posts on StackOverFlow that seem to be similar to mine, but nothing seemed to resolve my problem.</p>
  
  <p>(Edit 1)</p>
  
  <p>While the env is activated, I tried to run <code>pip install djangorestframework</code>, and I got this error message.</p>
  
  <pre><code>(new_app) sot232@ubuntu:~/new_app/bin$ pip install djangorestframework
  Collecting djangorestframework
    Using cached https://files.pythonhosted.org/packages/1b/fe/fcebec2a98fbd1548da1c12ce8d7f634a02a9cce350833fa227a625ec624/djangorestframework-3.9.4-py2.py3-none-any.whl
  Installing collected packages: djangorestframework
  ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/home/sot232/new_app/lib/python3.7/site-packages/djangorestframework-3.9.4.dist-info'
  Consider using the `--user` option or check the permissions.
  </code></pre>
  
  <p>(Edit 2)</p>
  
  <p>I run <code>pip freeze</code> and <code>pip3 freeze</code>. I received this result.</p>
  
  <pre><code>sot232@ubuntu:~/new_app/bin$ source activate
  (new_app) sot232@ubuntu:~/new_app/bin$ pip freeze
  Django==2.2.1
  mysqlclient==1.4.2.post1
  pytz==2019.1
  sqlparse==0.3.0
  </code></pre>
  
  <p>It seems like rest_framework is not installed on my virtualenv. However, <code>djangorestframework==3.9.4</code> is installed globally. </p>