find django/contrib/admin/templates - python

I have trouble to see django/contrib/admin/templates folder. It seems like it is hidden in /usr/lib/python2.7/dist-packages/ folder, ctrl+h wont help ( appearencely all django files are hidden).
"locate django/contrib/admin/templates" in terminal shows bunch of files, but how can i see those files in GUI? I use Ubuntu 12.10
Thanks in advance

To see where your django installation resides, run this at the command line:
python -c "
import sys
sys.path = sys.path[1:]
import django
print(django.__path__)"
On my system, this returns
['/usr/local/lib/python2.7/site-packages/django']
Source: Django Docs

You should not mess with your system-specific python setup because it is used as a dependency for other programs (which are use python). For example, a manual update of a package in /usr/lib/python2.7/site-packages/ can break a program and also requires root permissions.
Instead, you should create a virtualenv and install django in it:
# create an isolated python environment
virtualenv ~/your_env
# activate this environment, this means that you don't need to mess with your /usr system anymore
source ~/your_env/bin/activate
# use python's standard package manager to install django in the virtualenv
# does not require special permissions
pip install Django
# it will install in: ~/your_env/lib/python2.7/site-packages/
virtualenvs are isolated, safe, and work with your regular user permissions.

Should be here: /usr/lib/python2.7/site-packages/django/contrib/admin/templates

Since, everyone is posting my comment's suggestion, might as well post it myself. Try looking at:
/usr/lib/python2.6/site-packages/django/

I think you should be looking in site-packages. Assuming you're using django 1.4 it should be -
/usr/lib/python2.7/site-packages/django/contrib/admin/templates

If you are using Python3, Django is located at your venv. In my case templates are located at <project_root>/venv/lib/python3.5/site-packages/django/contrib/admin/templates/.

Related

Do others need to have the same modules installed to run my code in Python?

If I use a module such as tkinter, would somebody need to have that module installed as well in order for my code to run on their machine?
Definitely. You can use virtual environments or containers to deliver required packages or have a requrements.txt or similar to install the dependencies.
python comes with a number of standard modules pre-installed, if the other person is running python (the same version of you) then he/she won't need to install anything, it will just work, that's the case of tkinter. But if you use external packages that you installed to run your code, for example celery, then he/she will need to do the same thing.
If you gave your code to someone to run, they would need to download the same modules, unless you also sent the environment too. The only way I know around this is to freeze your code where you would create an executable. I've used cx_Freeze and pyInstaller and haven't had any issues but it also depends on your needs. You can find some more information through here:
https://docs.python-guide.org/shipping/freezing/
Hope this helps!
In your running environment do a, this file you add to your repo
pip freeze > requirements.txt
When people clone your repo, they only have to do a:
pip install -r requirements.txt
and they will install exactly the same pypi modules you have.
With virtualenv you can isolate a python environment to each project, with pyenv you can use different pythonversions withing the various environment also.

Importing my own private package in Python/PyCharm

I made a package that bundles some utilities I'm using across projects. What's an easy way to import this package each time I start a new project?
There's some private work data stored as variables in there, so I won't be uploading it onto PyPi.
I am using Python 3.7 and PyCharm, and in Project Interpreter attempted to put the /zhou_utils/dist as a 'URL' of repositories it searches for, but it threw an error.
Another solution I saw someone present was to change their local PATH, but I don't have admin privileges on my work computer so don't know if I can do that.
Running this in my terminal from my 2nd project worked:
pip install -e C:\Users\Uname\PycharmProjects\zhou_utils\

Proper way to customize third-party python package in project [duplicate]

I installed some package via pip install something. I want to edit the source code for the package something. Where is it (on ubuntu 12.04) and how do I make it reload each time I edit the source code and run it?
Currently I am editing the source code, and then running python setup.py again and again, which turns out to be quite a hassle.
You should never edit an installed package. Instead, install a forked version of package.
If you need to edit the code frequently, DO NOT install the package via pip install something and edit the code in '.../site_packages/...'
Instead, put the source code under a development directory, and install it with
$ python setup.py develop
or
$ pip install -e path/to/SomePackage
Or use a vcs at the first place
$ pip install -e git+https://github.com/lakshmivyas/hyde.git#egg=hyde
Put your changes in a version control system, and tell pip to install it explicitly.
Reference:
Edit mode
You can edit the files installed in /usr/local/lib/python2.7/dist-packages/. Do note that you will have to use sudo or become root.
The better option would be to use virtual environment for your development. Then you can edit the files installed with your permissions inside your virtual environment and only affect the current project.
In this case the files are in ./venv/lib/pythonX.Y/site-packages
The path could be dist-packages or site-packages, you can read more in the answer to this question
Note that, as the rest of the people have mentioned, this should only be used sparingly, for small tests or debug, and being sure to revert your changes to prevent issues when upgrading the package.
To properly apply a change to the package (a fix or a new feature) go for the options described in other answers to contribute to the repo or fork it.
I too needed to change some things inside a package. Taking inspiration from the previous answers, You can do the following.
Fork the package/repo to your GitHub
clone your forked version and create a new branch of your choice
make changes and push code to the new branch on your repository
you can easily use pip install -e git+repositoryurl#branchname
There are certain things to consider if its a private repository
If you are doing the custom module that you want hot loading, you can put your running code also inside the module. Then you can use python -m package.your_running_code. In this way, you can change the module in the package and reflect the result of your running code immediately.

How do you arrange your site-packages folder in python

I just downloaded django and installed it into C:\Python27\Lib\site-packages So now my site-packages directory seems rather unorganized with 5 separate folders a bunch ot text files and a python script. Should I create a sub directory in site-packages for the django package and store everything in there? If I do that will the python intrepeter know to look in the Django directory in the site-packages directory for the django package? Or will I have to change some environment variables around?
Thank you.
I'm not sure if you're asking it because this is something you need to know because of some complex setting you have. In case you are just want to install Django, you should follow the install instructions from their site:
pip install Django
the directory order in site-packages is an internal mechanism of your Python build and I don't think you should change it, unless you want to create your own package and want to learn more on how python find installed packages (and if this is the case I would start reading this document: http://docs.python.org/2/distutils/index.html)
As suggested in the comments to your question, and also in the documentation of Django, you should consider using virtualenv, especially when developing a webapp which will get deployed on a server with a specific Django version. Over time you'll see that you want to create other apps that require different versions of modules, and to still support the already existing apps you will need to use virtualenv.

Django installed apps location for classes on system path

I'm using the Django Registration class, it's great, but the last version shipped with an issue and it's no longer updated
I've installed it on my path (downloaded it then python setup.py install) then added it to my projects installed apps
I'm on debian, and It's copied itself to /usr/lib/python2.5/site-packages/registration
So far so great, but editing (hell, even deleting) has NO effect on my project
I'm guessing when you include a class in the django installed apps it's copied somewhere, but where?
As always, thanks for your time!
You could try the oldest trick ever to figure out where it's coming from:
import registration
print registration.__file__
I would suggest that you try the following workflow:
Create a new virtualenv for every project you start (use --no-site-packages)
Install all your dependencies (including django) in the project's virtualenv
Use pip install -e to install things you need to have an editable version of.
Alternatively, fork the project, and install using pip install -e hg+http://...
I'm guessing when you include a class in the django installed apps it's copied somewhere, but where?
That's completely a wrong guess.
A better guess is that your download directory is on your Python path.
Somehow you had two copies (or more) of the module.
You've deleted some, but not all of the copies.
Keep searching on your PYTHONPATH for all the others. Search every directory in sys.path.
Note that .pth files in your site-packages directory are also part of your PATH.

Categories