I\'m following the Django tutorial https://docs.djangoproject.com/es/1.10/intro/tutorial01/
I\'ve created a \"mysite\" dummy project (my very first one) and try to
What am I wondering is though the django is installed to the container it may not be in the host machine where you are running the command. Then how will the command run. So since no above solutions worked for me.
I found out the running container and get into the running container using docker exec -it <container> bash
then ran the command inside docker container. As we have the volumed container the changes done will also reflect locally. What ever command is to be run can be run inside the running container
I solved this problem to uninstall the multiple version of Python. Check Django Official Documentation for Python compatibility.
Django 2.1 supports Python 3.5, 3.6, and 3.7. Django 2.0 is the last version to support Python 3.4."
manage.py file
#!/usr/bin/env python
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'work.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise 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?"
) from exc
execute_from_command_line(sys.argv)
If removing "from exc" from second last line of this code will generate another error due to multiple versions of Python.
The following could be the possible reasons,
1. The virtual environment is not enabled
2. The virtual environment is enabled but the python version is different
To create virtual environment
$ virtualenv --python=python3 venv
To activate the virtual environment
$ source venv/bin/activate
I was also getting the same error.
Then I went back to the folder where the environment folder is there and I forgot to activate a Virtual environment so only I was getting this error.
Go to that folder and activate the virtual environment.
$ source env/bin/activate
first with terminal cd into the directory containing manage.py
then type $source <myvenv>/bin/activate
replace with you Virtual Environment name, without angular brackets.
Another issue can that your root directory and venv mis-match. The structure should be something like this:
|-website
..facebook
..manage.py
..myvenv
..some other files
That is your virtual environment and manage.py should be in the same folder. Solution to that is to restart the project. If you are facing this error you must haven't coded anything yet, so restart.
After testing with precise instructions (using python2 or python3 instead of just "python") I've constated that no matter what the tutorial says, this works ONLY with python3.