Running django-admin tutorial erros: no module named django - django

I just started to try and install/run Django on my cmd prompt and faced this issue although environment variables are set up for Django.
Besides getting a solution, can someone help me understand the root cause of the error below?
C:\Python>django-admin startproject test
Traceback (most recent call last):
File "C:\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\windows\syswow64\scripts\django-admin.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'django'

In python based project it is always good to create Virtual Environment and then run your django program .
pip install virtualenvwrapper-win
mkvirtualenv test
workon test
this will activate your virtual environment
Now install django
pip install django
After django installation complets
run
django-admin --version
Hope this helps.

On windows, go where you want to create your project, and call from there the django-admin.exe:
path\to\django-admin.exe startproject project_name
Its not a clean solution but worked for me.

Related

After installing spyder django is not working

I installed spyder on my ubuntu system From which django is not working. The error it is showing when i ran the server the error showing is is
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: 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
ModuleNotFoundError: 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?
I need both spyder for OpenCV and also Django. can anyone help
It is working after doing
python3 -m pip install django
thank u mr sahil
The error means that the Django is missing from your system, if you have installed the dependencies in your virtualenv you will need to activate that, or you can just do
pip install django --user
If you have a virtualenv do this,
Linux
source path/to/venv/bin/activate
Windows
path/to/venv/bin/activate
First create a virtual environment, using the following command
python3 -m virtualenv venv
If you get an error saying something similar to this, Virtualenv module not found, you will need to install virtualenv using pip by the following command.
pip3 install virtualenv
Then use the aforementioned command to create the virtual environment.
To activate it just use
source venv/bin/activate
This will activate the virtual environment. Now install Django on it.
pip install django
You don't need to specify a pip version (say pip3) because the virtual environment is created in python3 so pip defaults to pip3 itself.
Now finally run your server
python manage.py runserver localhost:8080

ModuleNotFoundError: No module named '_sqlite3' python django

I am running simple python manage.py runserver and getting this error :
File "/usr/local/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
I had tried everything like installing sqlite3,sqlite-devel but nothing works.
Try to make a new virtual environment with virtualenv, conda or any other way you know and then activate your virtualenv, install any package you need inside that to avoid versions conflict problems. Now you can run the app.
Hope this works

Permission error when installing Django within virtual environment

I have Django 1.10 installed within a virtualenv on my machine. Now I am creating another virtualenv (for another project) and installing Django 1.11 on it using the following command:
pip install Django
but I get a permission denied error:
Collecting Django
Using cached Django-1.11.5-py2.py3-none-any.whl
Requirement already satisfied: pytz in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from Django)
Installing collected packages: Django
Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/wheel.py", line 377, in move_wheel_files
clobber(source, dest, False, fixer=fixer, filter=filter)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pip/wheel.py", line 323, in clobber
shutil.copyfile(srcfile, destfile)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.5/bin/__pycache__/django-admin.cpython-35.pyc'
I have read multiple SO posts about this but their solutions dont seem to apply to me. Please note:
1) I have already activated the new virtualenv before running the command.
2) I did not create the new virtualenv using sudo. I just did the following to create it:
virtualenv name-of-the-new-virtualenv
What could I be missing?
When using bash, the version of python being resolved in the PATH can be seen at any time by using which python.
You can also check the location of your sourced virtualenv by viewing the VIRTUAL_ENV environment variable (e.g. echo $VIRTUAL_ENV).
In this case, the issue was that the virtualenv directory had been moved after being created, so the PATH environment variable wasn't getting populated with the virtualenv's correct bin directory upon sourcing. One solution for moving a virtualenv is to make it "relocatable", which is explained in this answer.
Virtualenvs can be activated by sourcing the activate script:
source /path/to/my/venv/bin/activate
When any virtualenv has been sourced, it can be deactivated by using the deactivate function:
deactivate

bzt 1.1.0 says DistributionNotFound: selenium

I just installed bzt 1.1.0 on my MacOSX but it won't run, it gives this message:
Traceback (most recent call last):
File "/usr/local/bin/bzt", line 5, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
working_set.require(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req) # XXX put more info here
pkg_resources.DistributionNotFound: selenium
The thing is, selenium 2.49.2 was installed along with bzt. How can I fix this?
Turns out it was a Python package management issue. Selenium was installed in /Library/Python/2.7/site-packages with a selenium-2.49.2.dist-info directory, not the .egg-info directory that pkg_resources.py expected.
Upgrading to a newer version of pkg_resources helped, as explained in this answer:
sudo pip install --upgrade setuptools
Then, reinstalling selenium finally fixed the problem:
sudo pip uninstall selenium
sudo pip install selenium
Thanks to Andrey Pohilko on the Google Groups forum for helping out.

Django_extensions failing to work with iPython notebook

I am using Django 1.4.5 and have just installed django-extensions, in a virtualenv. I am using Python 2.7.1. When I type:
./manage.py shell_plus --notebook
I get the error:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/.../lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/.../lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/.../lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/.../lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/Users/.../lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/Users/.../lib/python2.7/site-packages/django_extensions/management/commands/shell_plus.py", line 140, in handle_noargs
run_notebook()
File "/Users/.../lib/python2.7/site-packages/django_extensions/management/commands/shell_plus.py", line 71, in run_notebook
from IPython.frontend.html.notebook import notebookapp
ImportError: No module named IPython.frontend.html.notebook
Without the --notebook option it works fine. Also, ipython notebook works fine too.
Can anyone suggest what might be going wrong?
thanks!
I solved this by using a new virtualenv, and making sure I had installed iPython in it, i.e:
pip install tornado
pip install pyzmq
pip install ipython
./manage.py shell_plus --notebook
In addition to what user [https://stackoverflow.com/users/905720/racing-tadpole](Racing Tadpole) said above, I also had to install jinja2.
pip install jinja2
A way to test what is missing to have django shell_plus on ipython notebook is trying to execute ipython notebook alone. This way I could detect all missing libraries, like jinja2.
ipython notebook
If this works, your chances are high that shell_plus --notebook will also work.