Setting mod_wsgi, django python version - django

I'm having trouble setting up the correct python version for mod_wsgi / django setup.
After numerous bugs I think i'm nearing the end of this tedious setup... I'm trying to run a command from my manage.py file using ./manage.py collectstatic
This is failing because it's trying to use the Python 2.4 version (I have 2.7 installed as well), I believe the version error only occurs when i manually try and run manage. My django.wsgi file inserts the python 2.7 dir into sys.path
Thanks for your help

python2.7 manage.py collectstatic worked. Thanks to Display Name for the comment

Related

telling the cmd what version of python im using

IM trying to make a website with django and im following a tutorial that is telling me i need to tell my cmd prompt what version of python im using. this is the video https://www.youtube.com/watch?v=FNQxxpM1yOs at the 10:46 mark he says to put C:/Python35/ python manage.py runserver. I am putting thi but it is not working. I am using version 3.7 so i replaced 35 with 37 but it is still not working. can someone please helps with this.
Not sure if it's different depending on OS, but I'm on Linux and use python3 manage.py runserver since I have python 2 and 3 installed. Using just python tries to use python 2, which I'm guessing isn't the version of Django you installed. I also use pip3 when I need to.
It seems like you are on Windows, you can do where python in your shell (which is pretty similar to which command on Linux) to locate your python.
If you installed python correctly then python should be already in your $PATH, in this case, as suggested by #marsonfire, just run python manage.py runserver or python3 manage.py runserver in your project folder.

import django ModuleNotFoundError: No module named 'django' after install python 2

I have 3 django projects (version 1.11.15), and all errors after I accidentally install Python 2 (I installed the react native), before I used python 3.6.5 via Anaconda.
Some of my project files appear error symbols. And when I try to run "manage.py runserver", it can't run, and an error appears. I uninstalled Python 2, and reinstalled my Anaconda (Python 3.6.5), but it didn't work.
In my opinion there is a problem in the path, but I don't know what that is. I've been looking for a solution, but nothing works. Anyone has a solution? ... thanks
my python version
this is my python path, I don't know what to add here, I just followed a few tutorials that I found
this is my path
This is my requirement.txt
enter image description here
i found it,
it's " python manage.py runserver " not " manage.py runserver "
I have ran into this problem and I found the easiest solution was to write out requirements.txt and remove any unwanted libraries. Then delete the virtualenv and recreate a new with the new requirements.

Python manage.py startapp does not work

When I run the python manage.py startapp "app name" command in my Django project directory nothing happens... Every other manage.py command works without problem.
What could be the problem?
Thanks a lot!!
Andrew
The first line in manage.py breaks the file on windows. The first line should look like this:
#!/usr/bin/env python
Removing it fixes the issue for me. Please try this is really helpful. Thanks
This problem occurs due to Python Path is not set, you can reinstall python and check the box that says "Add to Path 3.9"
Are you running the correct version of Python and correct version of Django?
To check Django:
python manage.py --version
Make sure you are running the right versions, if you are have Python 3 and Python 2 installed you may have multiple versions of Django.
Try to set environment variables on the command line? This path is if you were using vagrant.
PYTHONPATH=/vagrant/www DJANGO_SETTINGS_MODULE=settings django-admin.py startapp
Then try manage.py does it work? Without setting envs on the command line?
Adding a virtual environment is necessary to get the above command working. In the virtual environment you can specifically install Django and it is done so as to ensure that no other package interfers with the Django framework. I was also facing the same issue but after creating a virtual environment, things became super easy!!!
I would recommend using pycharm as creating a virtual environment is just as easy as running a hello world program!!. Also paste the following code at the settings.py script at the end :
ALLOWED_HOSTS=['*']
Also specify the correct directory while running in the terminal. Be sure to check that the code should be written inside the project directory.
Hope that helps :)
I was facing a similar issue and saw this question. Tried the methods mentioned by some of the users but it did not work. Surprisingly the only thing I had to do was remove the word "python" from the command. All I typed in the command line was - manage.py startapp "appname"
I have no idea what difference does it make or how I made it work, but if anyone has a similar problem I hope your issue gets resolved.
I think it maybe because i had previously added the directory I am working in the PATH variable. Not sure. Someone has an opinion on this, do share.
I think i may have found the solution. If you're running on python 3.7 or above, try setting your directory to ~\YourProjectName\YourProjectName with the cd commmand then type py -m django startapp <appName>
The command
$ python-admin startapp main
returns the error " bash: python-admin: command not found".
I was able to resolve using the following command instead
$ py -m django startapp main
if some of you are following old tutorials on django then after you have python version 3.7 or above then the command "python manage.py startapp 'appname'" doesnt works.//well it didn't work for me so insted of that command you can use "py -m django startapp 'appname'"
it worked for me so you can also try that..
the command -> manage.py startapp 'appname'" works for python version upto 3.7 and for 3.7 and above version used command -> "py -m django startapp 'appname'" it works for me...

django framework runserver not working

Django server isn't working on the command: python manage.py runserver (on providing the port number as well)
I'm using windows 8, the path is set in environment variables. I've tried re-installing both python and django but it didn't help.
I share the similar problem. I solved it by just running Python 2.7x.
While working with the runiserver
python manage.py runserver --noreload
also worked for me - at least for a while. Maybe install an older version of Django?
I've not literally found a solution...
however it worked when I used python 2.7.13 (this creates a folder where you've scripts, easy_install etc., but I couldn't find a folder "Python" when I was using Python 3.6.1)

django wont work with python3.3.3

Hello I recently installed the django on my Mac OS X 10.9 using the pip install Django.
The installation was successful, now my python3.3.3 is installed in the following directory:
/usr/local/lib/python3.3/site-packages
Inside this directory there is a directory for django so I am assuming that the installation was success on python 3.
The problem arise when I am trying the following procedure:
django-admin.py startproject mysite
The above command creates with success the directory with the files
Then on this command:
python manage.py runserver
or
python3 manage.py runserver
The error is:
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
Moreover, I do find a solution but wont work. Was to change the first comment of the file django-admin.py to link the compiler to the correct version of python, which was fine, but the problem is the same.
Any help?
Check out this tutorial on python development on OSX: http://hackercodex.com/guide/python-development-environment-on-mac-osx/
Virtualenv allows you to create sandboxes where you can install different python versions and python libraries without interfering with other virtual environments or with your system python version/libraries.
Your specific problem though, seems to be that Django was not added to your system path, so python doesn't know where to find the django files. It can be risky to add new things to your system path because it could end up conflicting with existing libraries.
If you use virtualenv, each environment will have its own "system" path and the python executable in that environment will know where to find the django files.