What does install django-app as a user library means? - python

I just finished my first Django-app and I now have a .tar.gz file. (It's my first one ever: :'))
After having the .tar.gz file I was like ok... now what's next? How do I install this? I found this question: How do I install Python/Django Modules? And I was reading #Miku answer to the question and I was thinking: Ok, if I just do pip install --user django-polls/dist/django-polls-0.1.tar.gz (from Advanced tutorial: How to write reusable apps documentation!) that means that my django proyect should be able to find my app after I add the app to
INSTALLED_APPS?
Because I was following the tutorial and I had the app folder right next to manage.py file. And know pip says my app is installed and not folder has been created in my project directory.
If this is a really stupid question, please, pardon me, I'm really new to django. :-)

When you install a python package as a library, it's installed to the python's packages folder, so it can be used from anywhere in the system.
So yes, your Django project should be able to find your app when you add its name in INSTALLED_APPS. If your app doesn't have its own models, you don't even have to include it in the installed apps, and just import from it when you need to use it.
I'm not sure what system you are on, but in Linux, usually installed python packages are located in /usr/lib/{PYTHON VERSION}/site-packages/
(just for a reference)

Related

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\

Enable module modification in virtualenv

I have 10 django projects that use over 50 django apps. Each app is separated in its own project and added to pypi and is getting use by few project. Every thing if fine except every time i work on a project and i want to change some code that is in one of my modules (that happens a lot) I have to open the module project, make my changes, test and publish to pypi then come back to my project update requirements.txt file and get the updated module from pip.
I'm looking for a way to be able to edit module right away from all of my projects. For example instead of getting it from pypi i want to get it from git and be able to commit to the git repository in my venv folder!
I know it seems a little bit crazy but i could save a lot of time! publisher and user of all of the modules is me so I don't mind the user to be able to change as well.
Any thought or suggestion will be appreciated. Also any none pip solution will be fine as well like writing a custom shell script.
I don't know about editing in your venv folder, which I think is not a good practice, but you can install from github by pip. You can use 'pip install git+https://github.com/urltoproject/repository.git'. Fill in the necessary details yourself of course. This also works with other systems like gitlab. You could have a separate development requirement file and a production requirement file to separate the two environments, or you install on the commandline directly with pip.

How to make my python project deployable?

In my free time I am developing a small python project based on django. I use several other python packages to improve user and my development experience.
I have understand, that I run pip install pkgname to install a module named pkgname and then I use from pkgname import somewhat and go one and everything is fine and fluffy. I understand why to use virtualenv and already use serious tools like coverage and travis-ci.
Now, I want to the next step. At the moment, my project is not ready for world wide deployment. But I like to prepare for this as soon as possible. It's called Palco and hosted on GitHub.
Usually, I think, pip is the current default to install python modules. But the application I develop is nothing developers will use in their project but users will. So, nobody will do pip install palco and then write from palco import hellyeah. But they will configure their favourite web server to run django's wsgi-handler.
Currently, I would tell people,
please download this archive.zip, extract it and configure your webserver as mentioned
But this is a very php-way of deployment (just throw your files in a directory).
How make I my end-user python project deployable? Do I need a setup.py? Do I miss something?
I know, trac is installed with pip and then I "deploy" my very on trac-instance with trac-admin.py. Should I have a palco-admin.py with the same magic effect as trac-admin?

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