Django: setup.py versus copying directory - python

On windows 7 I have python2.6.6 installed at C:\Python26
I wanted to install Django, so I:
downloaded and untarred the files into C:\Python26\Django-1.4
ran python setup.py install
verified it was installed by opening IDLE and typing, import django
The next part is the problem... in the tutorial, it says to now run django-admin.py startproject mysite, however django-admin.py wasn't found, and while looking for it, I discovered that there is a duplication in the directories
C:\Python26\Django-1.4\build\lib\django
C:\Python26\Django-1.4\django
I didn't see anything in setup.cfg that would allow me to make sure that didn't happen or to pick a different setup folder, etc... but in the file C:\Python26\Django-1.4\INSTALL, it is stated that "AS AN ALTERNATIVE, you can just copy the entire "django" directory to python's site-packages directory"
So for my question: besides avoiding this duplication of code in the Django directories, what else is the difference with using the setup.py install command versus copying the directory? Are there other pros/cons?

Try adding "C:\Python26\;C:\Python26\Scripts;" to your PATHenvironmental variable and then running django-admin.py startproject mysite.

Related

Undo changes of '2to3' library

I had some python code in my SSH Project Folder which I had to convert from Python 2.7 to Python 3.*. Hence I installed the library 2to3.
However, before running the command 2to3 . -w, I navigated to the ROOT directory which contained all the Python and Conda relevant library files by mistake and ran my code from there.
So I think that has changed all the python files from the root directory and not just my project-specific files. Hence I am getting multiple errors now while running the code.
By any chance, is there any way to undo these changes? I tried conda update --all to upgrade my packages but nothing is happening. Is re-installing everything the only way to fix this?

Clear setuptools cache in pyramid?

I am pretty new to python and pyramid. I am working on pyramid application that I run with the following command:
pserve development.ini
When I make some changes and restart the server (kill it and run it again) it keeps the old versions of the files in cache.
I have noticed that I can clean the cache by re-installing the application with
python setup.py install
but I am sure that there is a nicer way for this?
I have noticed that the cache files are kept in the build folder:
build/lib.linux-x86_64-2.7/*
Instead of using python setup.py install, use python setup.py develop. This will link your application's directory into the site-packages without creating a separate "installed" source tree.

django-admin.py startproject mysite is not doing anything

It worked when I did the poll tutorial in linux, but I'm doing it again in Windows 7, and it does nothing.
I already set the environmental variables, and set the file association to my python27.exe
When I run django-admin.py startproject mysite from the DOS command prompt, it executes, but it's showing me all the information (Like the options, etc) as though I typed the help option instead. It's not actually creating project files in my directory. I appreciate the help.
also, I tried the solution found here (it appears to be the exact same problem).
It did not work
django-admin.py is not working properly
I ran into the same problem.
Never having worked with Django before but having worked with Python 2.7 a fair bit, all on a windows 7 platform. I downloaded the latest version of Django and unpacked it on my desktop.
After mucking around a bit managed to get it to install itself. I found could not just follow the tutorial thats provided in the docs googled the problem and found this thread, now I was able to get it to work by doing the following things,
I work with a dos command window open. I navigate to the root of where I want the project file to be set up. I then ensure that the django_admin file has been editted as per wynston's instructions and then typed the following.
python c:\location of django_admin.py startproject projectname
and it executed beautifully.
*Thanks to wynston for the edit to the django_admin.py file.
Try to run python27 django-admin.py startproject mysite from the command line,maybe a different (older) python.exe executes the django-admin.py file. If there's a program associated to the .py files, things mixes up, and your path environment variable doesn't matter.
I suggest you to use virtualenv. When you use it, you should put the python.exe before every .py file you want to run, because the install of python will associate .py files to the installed python.exe, and will use that, whatever is in your path. :(
Change the first line of django-admin.py #!/usr/bin/env python to for example
#!D:\Program Files\Python\python.exe (Where you install your python.exe,that's my directory), it works.
Use python django-admin.py startproject mysite. That worked for me some time ago when I had the same issue.
The solution is simple in Windows:
1-Go to C: \ Python34 \ Scripts
2-Right click on django-admin.py
3-Select open with
4-Select default program
5-Select Laucher Python for Windows (Console)
6- Run the command in CMD Windows python django-admin.py startproject mysite
Great answers. But unfortunately it did not work for me. This is how I solved it
Opened django_admin.py as #wynston said. But the path at first line was already showing #!C:\ correctly. So did not had to change it
I had to put "..." around django-admin.py address. Navigated to the project directory in cmd.exe and ran this
python "C:\Users\ ......\Scripts\django-admin.py" startproject projectname
It worked only with the quotation marks. I am using Anaconda Python 2.7 64 bit, on Windows 7, 64 bit. Hope it helps

Why does django open with pype?

when i type in the command prompt
django-admin.py startproject mysite
the django-admin.py will open automatically with pype,
now if i type cd mysite it says the system cannot find the path specified
I'm using activepython (i don't think that activepython has anything to do with it), django installed using pypm. I can create a project in pydev, not in the command prompt, about a year ago when i first installed activepython, it used to work but as far as i can remember i deleted a django project and it won't work anymore.
how to fix it?
EDIT
#Mikko Ohtamaa
mysite folder does not exist,i see on pype that it has opened the file from C:\Documents and Settings\Administrator\Application Data\Python\Scripts\django-admin.py
but the path is incorrect i don't have an application data folder in C:\Documents and Settings\Administrator\
I have searched the entire pc and haven't find a folder, furthermore in you run this 100 times
django-admin.py startproject mysite
it will keep opening a file called django-admin.py you know, nothing else
"but the path is incorrect i don't have an application data folder in C:\Documents and Settings\Administrator\"
This would mean that your Python or Django installation is corrupted (probably due to reinstall Python).
Try go to square zero and reinstall both Python and Djangon on your computer. Also if it still does not work please describe how did you install both of them.

How do I update my version of Django?

I currently have it installed and it's running a website.
http://www.djangoproject.com/download/
This is the new version. How do I upgrade it? (How do I install the new version over my current one?)
read about this in :
http://docs.djangoproject.com/en/dev/topics/install/
For installing Django to be able to update to the latest code in trunk:
If you'd like to be able to update
your Django code occasionally with the
latest bug fixes and improvements,
follow these instructions:
1.Make sure that you have Subversion installed, and that you can run its
commands from a shell. (Enter svn help
at a shell prompt to test this.)
2.Check out Django's main development branch (the 'trunk') like so:
svn co
http://code.djangoproject.com/svn/django/trunk/
django-trunk
3.Next, make sure that the Python interpreter can load Django's code.
There are various ways of
accomplishing this. One of the most
convenient, on Linux, Mac OSX or other
Unix-like systems, is to use a
symbolic link:
ln -s pwd/django-trunk/django
SITE-PACKAGES-DIR/django (In the above
line, change SITE-PACKAGES-DIR to
match the location of your system's
site-packages directory, as explained
in the "Where are my site-packages
stored?" section above.)
Alternatively, you can define your
PYTHONPATH environment variable so
that it includes the django-trunk
directory. This is perhaps the most
convenient solution on Windows
systems, which don't support symbolic
links. (Environment variables can be
defined on Windows systems from the
Control Panel.)
What about Apache and mod_python?
If you take the approach of setting
PYTHONPATH, you'll need to remember to
do the same thing in your Apache
configuration once you deploy your
production site. Do this by setting
PythonPath in your Apache
configuration file.
More information about deployment is
available, of course, in our How to
use Django with mod_python
documentation.
4.On Unix-like systems, create a symbolic link to the file
django-trunk/django/bin/django-admin.py
in a directory on your system path,
such as /usr/local/bin. For example:
ln -s
pwd/django-trunk/django/bin/django-admin.py
/usr/local/bin This simply lets you
type django-admin.py from within any
directory, rather than having to
qualify the command with the full path
to the file.
On Windows systems, the same result
can be achieved by copying the file
django-trunk/django/bin/django-admin.py
to somewhere on your system path, for
example C:\Python24\Scripts.
You don't have to run python setup.py
install, because you've already
carried out the equivalent actions in
steps 3 and 4.
When you want to update your copy of
the Django source code, just run the
command svn update from within the
django-trunk directory. When you do
this, Subversion will automatically
download any changes
For updating Django from stable release to another stable release:
If you are upgrading your installation of Django from a previous
version, you will need to uninstall the old Django version before
installing the new version.
If you installed Django using setup.py install, uninstalling is as
simple as deleting the django directory from your Python
site-packages.
If you installed Django from a Python egg, remove the Django .egg
file, and remove the reference to the egg in the file named
easy-install.pth. This file should also be located in your
site-packages directory.
First of all, don't. Install/upgrade it on your staging server first and test your app to make sure that it still works. Only after complete testing should you cut over to the new version on your production website.

Categories

Resources