I would like to learn Django on Windows.I have installed python 2.7.I am unaware of installing Django. I have googled a lot,but didn't understand properly.I referred this question ,But i didn't understood the third point in the accepted answer. I have installed python in c:\.Also django also in c:\.Please help me.I have extracted the django
I always used this link and everything worked like a charm (I didn't install iPython and didn't go through step 3):
http://www.swegler.com/becky/blog/2011/08/27/python-django-mysql-on-windows-7-part-i-getting-started/
I'm going to suggest some extra steps for you that will be invaluable in the long run. First, use virtualenv for your development. This lets you keep several separate Python environments on your machine, each tuned to the projects they're running. Keeping all your projects in a virtualenv also means, if you do something that breaks that environment's Python installation, the rest of your projects are unaffected. I use Linux so I've never installed virtualenv on Windows but this tutorial seems sensible.
Virtualenv has a package called pip installed automatically. Pip is a Python package installer. Using that, getting Django installed and set up is as easy as typing pip install Django at a command prompt. It also has lots of other really useful features for controlling and backing up Python environments that you can find in its documentation.
The 3rd point is where Django gets installed, if you are stuck on that point, you have not installed it yet.
You need to extract django to a folder, cd to that folder and run python setup.py install
The reason that the other answer has C:\download\Django-1.2.5> is that they extracted django to that directory and c:\Python27\python.exe because on windows, you need to reboot in order for path modifications to take effect. So instead, they are accessing the python executable directly with no need to reboot.
To check if you have successfully installed django you can do the following (yes, will work for windows)
(virtualenv)[root#localhost ~]# python
Python 2.7.4 (default, Apr 8 2013, 14:05:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'1.5.1'
open up cmd, type python (as long as you added it to your path)
then type import django
followed by django.get_version()
If you did it successfully, there will be no import errors and you will see the version of django that is installed.
Related
I know that many have posted similar question however I tried most solution without success.
I'm trying to host a webpage with apache2 and django in python3.
In the error log I found ImportError: No module named 'django' when accessing the wsgi.pyfile, where I also added import sys, sys.version to confirm which python version is used and from the error log I can see that I'm running following python version 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609].
When I run python3.5 I see that I uses the same python version and here I can run import django without any error!
EDIT: I checked django.__file__and saw that it was located in /home/USERNAME/.local/lib/python3.5/site-packages/django/init.py and that path /home/USERNAME/.local/lib/python3.5/site-packages wasn't in the sys.path that tried to run django. But adding it with sys.path.append(path) didn't help :(
Any thoughts what I might have messed up?
If you have Setup the whole configuration in VirtualEnv then , i suggest you to activate it by,
source /location to /env/bin activate
pip3 install django=version_id
or pip install django=version id
if you want to pass version id then its good or it will install the latest django from your repo.
Now test Django Version there.
Hope you will no get the error.
Location - means the path where env will be located in project directory, if you have followed the standard installation process of django or else you don't need, and version id- vesion of django framework.
I finally understood how to solve it! first I had to run pip3 uninstall django then run sudo pip3 install django.
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/
I am using Django on my Mac OS X server. Things are fine, so far. I have been using python 2.6.1 and all works well. I upgraded Python to version 2.7.3. Invoking python in the terminal brings up version 2.7.3, as expected. Checking Django using the {% debug %) reveals that Django is still using the original python 2.6.1 interpreter.
On this system, /usr/local/bin contains a symlink to ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python
In /usr/bin I find the python interpreter, and from that directory, invoking ./python gets python 2.6.1 running.
My $PATH is
/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/mysql/bin:/usr/local/bin
which I believe must have been altered on the python 2.7.3 install.
What is considered the optimal way to get the command line and Django using the same Python? I am considering either moving the framework version to /usr/bin and sitting a symlink in the framework to the moved new version. On the system is also a /Library/Python directory, that contains the site-packages for versions 2.3, 2.5, and 2.6. In /Library/Python/2.6/site-packages are the major goodies django, mercurial, and south.
Where are people putting things, nowadays? I mean, I know I could move things around, but I would like to anticipate where the Django project is going so future upgrades can go smoothly.
Install it against the updated Python.
Consider putting your app within a virtualenv container and specifying the version of Python when you create it - as per: Use different Python version with virtualenv
I cannot find a good source of information on how to upgrade Django to 1.4 on TurnKey Django (based on Ubuntu 10.04). I did not worked at Unix machine for a long time and I am a bit lost. Some IRC channel?
The best way to do this is to install django 1.4 in a virtual environment.
First, install virtualenv (if its not installed already sudo apt-get install python-virtualenv)
Then, install django 1.4:
$ virtualenv --no-site-packages django_1_4
$ source django_1_4/bin/activate
(django_1_4) $ pip install django
(django_1_4) $ python
Python 2.7.3 (default, Apr 20 2012, 22:44:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'1.4'
After your comment, I have another suggestion. Since this is a single purpose machine, you can simply upgrade the global version of django on your machine.
First, to avoid conflicts, uninstall django if it was installed from apt:
apt-get remove --purge python-django
Then, since you already installed python-virtualenv from above, you can do this:
$ sudo pip install -U django
This will upgrade (or install) django to the latest version available to the global site packages directory.
Then you can do the same import django and then django.get_version() and it should return 1.4.
While I am having a hard time finding an official source with version information, it seems to me that the latest Django release for TurnKey Linux is (as of Dec. 2011) at most version 1.3.1.
Check out this mail archive question and click through the threads for more information. They discuss setting up the latest version of Django for TurnKey Linux using tools such as virtualenv to ensure that you are able to continue to use older (outdated) packages if need be.
I installed python 2.6 alongside my mac's 2.5.2 version. As soon as I did, python2.6 manage.py runserver failed because it couldn't find django.core.management.
From a shell, import django returns importerror: No module named django.
Why?
Did you reinstall Django?
This happens when I install side by side versions of Python on Gentoo. Whenever I install a new version, I have to either reinstall the new ones or make a symlink to the old site-packages.
Because each installation of Python uses its own directory to store libraries. On a Mac, they are in /Library/Python/2.x/site-packages/. Presumably you originally installed Django in the 2.5 directory, but it isn't yet in the 2.6 one. You can symlink it there if you want to, or reinstall it using the new version.
Add site-packages to PYTHONPATH:
export PYTHONPATH="/home/jerome/bin/django-1.1/lib/python2.6/site-packages:$PYTHONPATH"
Worked on Ubuntu, with a python/django virtual environment using virtualenv and pip.
Source: http://benfsayer.com/importerror-no-module-named-django-core-management/
I use Bitnami's Django installer, and this happened for me when I wasn't in their custom shell, which I believe sets related python path environment variables. I ran ./use_djangostack in the root of the Bitnami package and then was successful running the server again.