1

I have two Django projects and I created two different virtualenv for them. When I create another one virtualenv and install Django and create a django project I tried python manage.py runserver and have this error:

Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    import django
ImportError: No module named 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 17, in <module>
    "Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

What I need to do? I already tried uninstalling Django, pip, virtualenv and re-install:

sudo apt-get install python3-pip
sudo pip3 install virtualenv
sudo virtualenv ENV
source newenv/bin/activate
sudo -H pip3 install django
2
  • 2
    When you are in an active virtual env, you just run pip install... no sudo, no pip3. Commented Oct 9, 2017 at 16:55
  • then i get:Exception: Traceback (most recent call last): File "/home/morilon/dj/ENV/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/home/morilon/dj/ENV/lib/python3.5/site-packages/pip/commands/install.py", line 342, in run prefix=options.prefix_path, File "/home/morilon/dj/ENV/lib/python3.5/site-packages/pip/req/req_set.py", line 784, in install **kwargs File "/home/morilon/dj/ENV/lib/python3.5/site-packages/pip/req/req_install.py", line 851, i Commented Oct 9, 2017 at 17:00

1 Answer 1

1

Using sudo with virtualenvs can cause a lot of scope issues, as well as a virture of virtualenvs is that you shouldn't need root permissions for them (in most cases).

Also if you have virtaulenv installed for python 2 as well, it might be defaulting to that one.

sudo apt-get install python3-pip
sudo pip3 install virtualenv

# I prefer using this over `virtualenv --python=/usr/bin/python3 ENV`
python3 -m venv ENV 
source ENV/bin/activate

# Can do a `which pip3` here to make sure it's using the ENV one
pip3 install django

# Could also do full path of `ENV/bin/pip3 install django`
Sign up to request clarification or add additional context in comments.

1 Comment

Glad to hear @Dorian, would appreciate the answer being accepted if you don't have further issues, Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.