I\'ve already configured virtualenv in pycharm, when using the python manage.py command, this is error shown:
E:\\video course\\Python\\code\\web_worker\\MxO
You can use python3 to run file, if you don't want to use virtualenv.python3 manage.py runserver
To install python3 look at this page
I solved this problem in a completely different way.
Package installer = Conda (Miniconda)
List of available envs = base, djenv(Django environment created for keeping project related modules).
When I was using the command line to activate the djenv using conda activate djenv
, the base environment was already activated. I did not notice that and when djenv was activated, (djenv)
was being displayed at the beginning of the prompt on the command line. When i tired executing , python manage.py migrate
, this happened.
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?
I deactivated the current environment, i.e conda deactivate
. This deactivated djenv
. Then, i deactivated the base
environment.
After that, I again activated djenv
. And the command worked like a charm!!
If someone is facing a similar issue, I hope you should consider trying this as well. Maybe it helps.
In case you have virtual env activated, django installed, django-admin --version prints the valid version - check if there is no circular import in the file you are executing.
Looks like you have not activated your virtualenv when using the runserver command.
Windows: <virtualenv dir>\Scripts\activate.bat
Linux: source <virtualenv dir>\bin\activate
You should see (name of virtualenv) as a prefix to your current directory:
(virtualenv) E:\video course\Python\code\web_worker\MxOnline>python manage.py runserver
When you install Django on your computer all things go fine but when you install a Virtual environment it gets separated from all things. You will know it's importance when you will make a final project and deploy it to any cloud or hosting.
Just reinstall Django in the virtual environment and baam:
pip install Django
and then just run the command for testing:
python manage.py runsever
and you are all done.
windows :
(virtualenv dir)\Scripts\activate # this step to activate virtualenv
you should be in the dir of (project name)
python manage.py runserver