how to package a django project? - python

How can i package a project so that i can just call some function that runs the project?
I know how to package a django app, but my question is how to package a django project.
Currently i have my project on an internal pypi server and can pull it down using:
pip install [project]
but then to use it i have to go into my site-packages and then the package just so i can run
./manage.py ....
Or am i just better off checking out the project and pip installing the apps?

One way, is to create a package using your distros package management system. At my shop, we use Ubuntu's aptitude. So package our software as a .deb using CMake.

It's probably not the best way to do it, but you can use distribute to generate wrapper scripts for you: http://packages.python.org/distribute/setuptools.html#automatic-script-creation

I had this same question with my own project. The solution, as the community around the project arrived at, was to package it in a number of ways for different platforms, but not as a PyPi module.
In order of popularity, my project is typically installed via:
Docker instance: docker pull <project-name> && docker-compose up
Cloning the git repo: git clone <url> && ./project/scripts/do-the-thing
Vagrant: vagrant up
If there was more support in the group, I suppose it would make sense to roll out a .deb, .ebuild, and .rpm, but at this stage, people seem more-or-less happy with the above.

Related

Is this the right method for distributing a python app with git and pip?

I write python applications for internal use at my company. Everyone has python installed on their machines, but they are not developers, so cloning a repo or creating a venv is outside of their skillset. I was hoping to change my apps so they may update themselves when I push an update to the git repo on a shared network drive. I would like the app code to update, but also the dependencies installed in each of their virtual environments.
I was thinking of wrapping my application in some code which, before importing any of the dependencies:
Checks if a venv exists
if it doesn't, creates one using the local requirements.txt
if it does, skips this step
Checks if the git repo version tag is more recent than the local git repo version tag
if a more recent version is available, it will pull from the master repo. The repo will only contain the app code and the requirements.txt
It will then pip install --upgrade the new or updated packages using the new requirements.txt file
if a newer version isn't available, it just runs the app
This all seems doable, and not terribly complicated, but I can't help but feel like I'm reinventing the wheel here. This seems a bit too manual and too common of a problem for there not to be a better way of doing this. What am I missing? What's the best way to handle this? Thanks for your help, everyone!

Django Error: cannot import name autodiscover_modules

I meet this error when I deploy my Django project on another VPS. The same codes can run successfully on my Macbook and a staging VPS.
My website based on Django 1.4.20, and import some third python library and Django apps, for example redis-py, requests, django-import-export, django-kronos, django-cors-headers. I install these by pip install etc
I'm really confused how these happen. Maybe it's a library dependency problem, but I can't find detail error log or stacks. Thanks for your time.
You should have a requirements.txt with your webapp. Then do pip install -r requirements.txt when you deploy.
If you did not make such a file, you can create one later by running pip freeze > requirements.txt. But beware that there might be some packages there that are not needed, if you installed other stuff on the side, so be prepared to manually screen the file.
If you work with multiple webapps you may also need to containerize your requirements (here's why). Two options: Docker or virtualenv. If you don't know what Docker is and don't have some time on your hands I suggest you go with Virtualenv for now.

How do I include library from github in python project without pip?

I'm not sure what's the python way to include another library getting from github.
I'm planning to use this library https://github.com/nim901/gfycat which right now I just downloaded the zip and extract it and put that in lib folder. I have to checkin this library into the repo to work in Heroku. Is there a way to install the lib automatically from github?
Heroku has support for git-backed python dependencies via pip: https://devcenter.heroku.com/articles/python-pip#git-backed-distributions
I believe this fits your requirements better than checking the actual libraries into git. From the link above:
Anything that works with a standard pip requirements file will work as expected on Heroku.
Thanks to pip’s Git support, you can install a Python package that is hosted on a remote Git repository.
For example:
git+git://github.com/kennethreitz/requests.git
You can add the library as a submodule of your project. This will allow you to update it like any other git repository.
Is git clone https://github.com/nim901/gfycat.git and then git pull automatic enough? If this solution fits you and you need additional instructions, I will add them.
From how I'm reading your question, it sounds like you're trying to install the module to your system in order to be able to import it into projects and such.
Download the zip, extract it to wherever, and open up a terminal window to the same directory. Then just run python setup.py install from within the directory, and it should install into your system-wide site-packages directory for python.
I would have to recommend that you install it into it's own environment managed by virtualenv (https://virtualenv.pypa.io/en/latest/), but it's not necessary.

Can I tar up a virtualenv so that I can distribute it as a package to anyone?

I have a django project set up in a virtual environment. I want to turn into a package (may be a tar), which I will just make available for download so that any one can just download, extract & run the project without any hassles of installing dependencies.
No, you shouldn't just simply make a tar of your django project and distribute it.
In the original documentation of Django there are instructions how reusable apps can be packaged and distributed. An explanation here would go beyond the scope of an answer. Please check the particular part of the documenation:
https://docs.djangoproject.com/en/1.8/intro/reusable-apps/
You can provide the dependencies for your package, which will be then automatically installed by pip.

django installing dependencies from git

Is there any way to tell django to install some dependencies through external repositories? For example, I'd not like to keep twitter-bootstrap code downloaded into my repository, I'd like to define a github link and fetch it automatically through a shell command. Something silimiar to collectstatic. I know I can write my own, but maybe there's something built-in or already implemented?
Python modules you can install directly from git. For example: pip install -e git+git://github.com/jschrewe/django-genericadmin.git
For frontend modules you can use tools like bower. For installing Twitter Bootstrap: bower install bootstrap
Both tools has config files, which can be used to track dependencies.

Categories

Resources