cannot run django_quiz app. manage.py not found - django

I was trying to install the django_quiz app that was found on github.
https://github.com/tomwalker/django_quiz
And as you can see below, i've installed all requirements. but there's no manage.py. How do i start and run the project?
Things I did >
Cloned the repo with git clone https://github.com/tomwalker/django_quiz.git.
Run --> pip install -r requirements.txt.
Run --> python setup.py install
Added 'quiz', 'multichoice', 'true_false', 'essay' to INSTALLED_APPS setting.
Added url(r'^q/', include('quiz.urls')), to urls.py.
NB: I'm a beginner in Django. Please help me. I'm kind of stuck here.
Django Version : 1.6.5
Installed c:\python27\lib\site-packages\django_quiz_app-0.5.1-py2.7.egg
Processing dependencies for django-quiz-app==0.5.1
Searching for Pillow==2.5.0
Best match: Pillow 2.5.0
Adding Pillow 2.5.0 to easy-install.pth file
Using c:\python27\lib\site-packages
Searching for Django==1.6.5
Best match: Django 1.6.5
Adding Django 1.6.5 to easy-install.pth file
Using c:\python27\lib\site-packages
Searching for django-model-utils==2.0.3
Best match: django-model-utils 2.0.3
Adding django-model-utils 2.0.3 to easy-install.pth file
Using c:\python27\lib\site-packages
Finished processing dependencies for django-quiz-app==0.5.1
C:\Users\Vaisakhan\django_quiz>python manage.py runserver
python: can't open file 'manage.py': [Errno 2] No such file or directory

I think this repo misses some steps. I think the steps should be as follows:
pip install virtualenv (you can skip this step and the next one if you are sure that there will not be any dependency error.)
virtualenv ~/quiz_env
source ~/quiz_env/bin/activate
pip install Django==1.6.5
django-admin startproject quiz_project
navigate to quiz_project/quiz_project, edit setting files
navigate to quiz_project/ and copy all the apps directory ('quiz', 'multichoice',....etc) inside quiz_project along with requirement.txt file
pip install -r requirements.txt
python manage.py syncdb
python manage.py makemigrations
python manage.py migrate
python manage.py runserver

Create a manage.py file and store it in the top folder of your file structure. Replace mysite with the folder holding your django quiz code.
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)

Related

django-admin pointing outside virtualenv

I've initialised a virtual environment using the virtualenvwrapper command mkvirtualenv -a <path to project> django_project.
I then installed django with pip install django. But then if i try to use django-admin i get:
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 7, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
Now pip list gives me
Package Version
---------- -------
Django 2.1.3
pip 18.1
pytz 2018.7
setuptools 40.6.2
wheel 0.32.3
python -m django --version gives
2.1.3
If I run which python it correctly points to my virtualenv, however which django-admin gives:
/usr/local/bin/django-admin
I'd think that it should point to my venv. Why would it point to a global django admin? How do I fix it so that it'll work for my future virtual environments?
I'm on MacOS using zsh and python 3.7.0.
Thank you!
Edit: Mistake in a command
Edit: I realised I don't have a system-wide installation of Django and so the django-admin and django-admin.py files in my /usr/local/bin must've been leftovers from an earlier installation. Hence I deleted them and that solved the problem. Without any further django-admin inside the venv point to the correct django installation (inside the venv).
However, I would still like to know why the command didn't point to the Django installed in the venv in the first place?
So Django has been installed at system level, while you verified that python command refer to your virtual environment. I bet this is an issue with pip. You may check that it is under <path to project>/bin and is correctly used when you perform
(django_project) $ pip install django
Try to run
which pip
with your venv enabled and disabled to see what pip is used in each case
I had the same problem, but after reboot it solved the issue for me.
Don't forget to check if the executable django-admin is inside the virtualenv's bin folder:
~/Documents/Django_python/django/bin $ ls
activate deactivate.nu pip3.10 wheel
activate.fish *django-admin* python wheel3
activate.nu pip python3 wheel3.10
activate.ps1 pip3 python3.10 wheel-3.10activate.csh
activate_this.py pip-3.10 sqlformat
(*) Highlight mine.

Django 2.1.1 Import Errors

i use vscode on windows10. I just created a Django project+app like this:
In the vscode powershell terminal:
python -m venv venv #createing a virtual environment called venv
.\scripts\activate #activate the virtual environment
pip install django==2.1.1 #install the newest version of Django
python -m pip install --upgrade pip #upgrading pip
pip install requests #install requests for api-requests
django-admin startproject api_order . #creates a django project called api_order
python manage.py migrate #create database
python manage.py runserver #starting the server
because of the server running in my powershell terminal i take a second powershell terminal and continue with activating the venv and creating a app.
.\scripts\activate
python manage.py startapp api_order_app #creating a app called api_order_app
When i now open the models.py python is reporting an problem "E0401:Unable to import 'django.db'" Same for all other imports in every other script.
What did go wrong?
I did this twice always the same problem.
This is how it looks like in the IDE
<img src="https://i.stack.imgur.com/JTmvb.jpg">
Thanks in Advance for helping me out.
Ben
I figured it out... I wasnt on the right virtualenvironment. But Django was only installed at the venv.
In Visual Studio Code you can choose the environment u want to use in the bottom left corner.
Now everything works just fine.

Deploy django as war - Jython

I'm trying to deploy a django app as war (to use with JBOSS server). I have seen the documentation and I made this:
jython manage.py builder --include-java-libs=/usr/share/java/jython/jython.jar
And I have this error:
Traceback (most recent call last):
File "manage.py", line 16, in <module>
raise ImportError(
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 should I do?
Thanks.
You have not activated that environment where you installed Python and other dependent packages for application.
Activate the environment and then run:
jython manage.py builder --include-java-libs=/usr/share/java/jython/jython.jar
Then it will work for you.
Try this:
jython -m pip list
In the list check the package name django is there or not. Also, check for package django-jython.
To install this package to jython installation directory, run this command:
jython -m pip install django
jython -m pip install django-jython
To build war file, use this command:
jython manage.py buildwar --include-java-libs=/path/to/jython-standalone.jar

Can't create django app in Conda environment.

I have created a conda environment by typing the following conda create --name testenv python command from here.
Now one of my tutorials tells me to install Django which I happily did in the environment(That is the point of using environments right?, keeping dependencies straight) using pip3 install django.Post which I was told to do this django-admin startproject mysite Which didn't work. I am thinking because he was doing it in venv and I am in conda probably that's why(There is no venv folder in my test-app folder as well. Also I have already activated the environment). Every time I type the command django-admin startapp mysite I get this error.
Traceback (most recent call last):
File "/usr/bin/django-admin", line 18, in <module>
from django.core import management
ImportError: No module named 'django'
How do I fix this? I have already installed Django. What more am I supposed to do?
This question is old, but if anyone is wondering the exact steps to create a Django application using conda, here it is
conda create -n <nameoftheapplication> python=3.6
source activate <nameoftheapplication> Note: For Windows just put activate
pip install django
django-admin.py startproject <nameoftheapplication>
cd <nameoftheapplication>
ls
You should see manage.py and a folder called <nameoftheapplication> which contains settings files.
Firstly, open the anaconda prompt in windows then go to the project directory and enter the following command:
conda create -n python=3.6 anaconda
activate
pip install django
django-admin.py startproject
cd
python manage.py runserver
Then open web browser and enter the http://127.0.0.1:8000/ to see django page.

Running Django in Virtualenv on EC2 -- ImportError: No module named django.core.management

I developed a django application locally, in a git repo. I launched an EC2 instance for the project and I set up a virtualenv with (what I believe to be) the correct packages/dependencies. I then proceeded to clone my repo into the virtualenv. Right now, I'm having difficulty as I'm receiving the following errors:
I attempted to use python manage.py runserver example.com/8080 to test. I was sure to activate the virtualenv using source bin/activate, just like I did in my local virtualenv. When I call ... runserver I get the following 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.core.management
Here is what sudo pip freeze produces:
Warning: cannot find svn location for distribute==0.6.24dev-r0
Cheetah==2.4.4
Django==1.5.2
Fabric==1.8.0
GnuPGInterface==0.3.2
Landscape-Client==12.05
M2Crypto==0.21.1
PAM==0.4.2
PyYAML==3.10
South==0.8.2
Twisted-Core==11.1.0
Twisted-Names==11.1.0
Twisted-Web==11.1.0
apt-xapian-index==0.44
argparse==1.2.1
boto==2.2.2
chardet==2.0.1
cloud-init==0.6.3
command-not-found==0.2.44
configobj==4.7.2
## FIXME: could not find svn URL in dependency_links for this package:
distribute==0.6.24dev-r0
django-s3-folder-storage==0.1
django-storages==1.1.8
django-tastypie==0.10.0
ecdsa==0.9
euca2ools==2.0.0
gunicorn==18.0
httplib2==0.7.2
keyring==0.9.2
language-selector==0.1
launchpadlib==1.9.12
lazr.restfulclient==0.12.0
lazr.uri==1.0.3
medusa==0.5.4
meld3==0.6.5
oauth==1.0.1
paramiko==1.12.0
psycopg2==2.5.1
pyOpenSSL==0.12
pycrypto==2.4.1
pycurl==7.19.0
pyserial==2.5
python-apt==0.8.3ubuntu7.1
python-dateutil==2.1
python-debian==0.1.21ubuntu1
simplejson==2.3.2
six==1.4.1
supervisor==3.0a8
ufw==0.31.1-1
unattended-upgrades==0.1
virtualenv==1.10.1
wadllib==1.3.0
wsgiref==0.1.2
zope.interface==3.6.1
...and this is my ./manage.py file:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
Any thoughts on how I can fix this error? I tried to change #!/usr/bin/env python to #!/var/www/paletto-env/bin python, trying to direct it to my actual python path, but it did not lend to any apparent change, so I changed it back.
Thanks for the help.
Looks like you're environment can't find Django, even though it's clearly in your pip freeze.
Try opening a Python (not Django) shell from your virtual environment and entering:
import django
django.VERSION
If you run into the same error, there's probably an issue with your Django install. Your virtual environment probably can't find it. You could try modifying the path settings, or just reinstall Django.
If you can successfully import Django, or if you tried reinstalling and it doesn't work, you may have a permission problem. Ensure that the user responsible for running the server has access to wherever your python libraries are stored from the virtualenv.
I had pretty much the exact same problem as you and this is how I solved it (Disclaimer: I'm not sure if this is the absolute correct way but it worked for me and everything seems correct).
Short Answer:
Try pip install (package) instead of sudo pip install (package)
Long Answer:
I gave the Django complete install doc (See here) a quick read through and came across a bit that basically said you dont need super user privileges when using pip in the virtualenv. I just assumed that either would be fine but I now realize that's probably not the case.
I suspect that because I entered sudo pip install django it installed it somewhere above my local bin in my virtualenv for the project. I suspect this because when I enter python manage.py runserver I get an error; however, when I enter sudo python manage.py runserver everything functions properly.
Also, typing sudo pip freeze reveals my larger library whereas pip freeze reveals my local library for my virtualenv.
I didn't want to type sudo (do stuff) before everything and I wanted a nice, clean and proper virtualenv so I just reinstalled django but to my local virtual env with pip install django and now django is in the proper virtualenv library, pip freeze returns the proper contents, and python manage.py runserver functions properly!
django-admin.py startproject by default creates the shebang in manage.py with #!/usr/bin/env python.
If this is not the path to your python executable, or if you use python3, just edit the manage.py to reflect this.
Reinstall all python packages angain after you have activated your virtualenv.
Maybe the Django has lost some plugin with pip, so we can install Django with Tarball:
Go https://www.djangoproject.com/download/1.6.5/tarball/
Download Django-*.tar.gz
install it.
$ tar zxvf Django-1.6.5.tar.gz
$ cd Django-1.6.5/
$ python setup.py install
more ... (https://stackoverflow.com/a/24323774/686105