telling the cmd what version of python im using - django

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.

Related

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)

Changing default Python from 2.7.10 to 3.5.2 in terminal so I can install pip

I was hoping for some help in setting up a Python development environment on a Mac.
Background: I'm running a newly upgraded macOS Sierra 10.12.1, and setting up various parts of Python development on it. This macOS version already came with Python 2.7.10 installed - and I'd prefer to leave that alone for now.
So I installed Homebrew, and then used that in turn to install the latest python3, that is, Python 3.5.2; but I guess it's not the default for Terminal yet, since when I run the python -V command, I get this in the Terminal window:
Python 2.7.10
So now I've got at least 2 version of Python on my Mac, and that's fine I guess, but the latest Python one is not the one that is the 'default'. How do I set 3.5.2 as my default rather than 2.7.10?
(Backstory for why I want to do that... pip is not installed, i.e., when I go to Terminal and type in pip, it says:
-bash: pip: command not found
When I tried to follow the installation instructions for pip, I ran into a permissions issue, which makes sense I guess, since I don't have access to the Mac's 2.7.10 Python install, nor do I really want it at this stage. So I'd like to switch Terminal to take the new Python 3.5.2 as my default one, in which case I guess I won't have pip permissions issues...)
Thanks in advance for any help folks!
The safest solution is to create a virtual environment running python 3 and use it as development environment. Check the following links:
https://docs.python.org/3/library/venv.html
http://docs.python-guide.org/en/latest/dev/virtualenvs/

Running Django written with python3 in Gunicorn

I've written a django site in python 3.2 and I want to run it by Gunicorn in my VPS with Ubuntu 12.04 OS and I faced errors for that belongs to python 2.7 but since it's not a good idea to change my default python to 3.2 in Ubuntu 12.04 I want to ask is there anyway to tell Gunicorn to run my project by python 3.2 not python 2.7?
Sure, install the other python, but don't change your ubuntu settings. When you create your virtualenv for your django project, use the -p flag to specify which python to use.
virtualenv -p /usr/bin/python3.2 [path/to/new/virtualenv/]
Alternatively, move the whole project to Heroku. There you can specify things such as python version, plus you can start ignoring a whole bunch of dev-ops stuff like this and spend more time writing your app. It's free, and you can get set up in a couple of hours.

Setting mod_wsgi, django python version

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