how to deploy apps developed in virtual env - python

I have a flask based app, and it's now running with virtualenv on my dev machine. Now I want to deploy it to my virtual host. Sadly, this virtual host is running flask 0.6, and I want flask 0.10. I don't have enough privilege to upgrade it.
Can I just upload my whole virtual environment, and to use my own version of flask, and how?
My idea is change the PYTHONPATH, how to get rid of the old version and add the new into it?
Any help will be appreciated.

Uploading your virtualenv probably won't work. There is a good chance that something in the virtualenv is dependent on the exact file paths and versions that won't match from your machine to the virtual host.
You can upload the virtualenv tool, make a new virtualenv, and then install the version of flask you want inside that virtualenv.

Related

Django Apps and Python Packages Dependencies

I am new to web development. I am not familiar with Django. I have written some Python scripts which do some intense calculations and graphs plotting using Python packages such as numpy, matlibplot and so on. I want to publish it as a web application on a server to be accessed by other computers.
So I am wondering, do I need to copy all the required packages into the project directory before deploying the application to a server? Or Django will automatically handle the Python packages dependencies upon deploying?
All the needed packages need to be installed on the server where is the web application running. If you have all the packages installed on your personal computer before deploy you will need to install the on the server as well.
You have to create virtual environment.
A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them.

Django app - What do I install in virtualenv vs system wide?

I'm working on creating my first "real" web app using Django.
Yesterday I learned I should be using a web server like Nginx to serve static files and pass off requests for dynamic content to my web app. I also learned that I need something like Gunicorn as the intermediary between the web server (Nginx) and my Django app.
My question is about virtualenv. It makes sense that we would contain app related software in it's own separate environment. What should I install in virtualenv, and what gets installed system wide? For example, in this guide we seem to install Python, Nginx and the database system wide (because they're installed before virtualenv is installed) while Django and Gunicorn are installed in virtualenv. It makes sense that Gunicorn would have to go in the virtualenv since its importing our python app, as explained here. Are the other things required to be installed system wide? Or can I pick either way? Is one way preferred over another?
Thanks!
Virtualenv is for managing Python libraries. It is not for managing Python itself, or for external services such as databases; it does however manage the Python libraries you use to access the database.
There's no room for confusion here, because there's simply no way to install Python itself or a database within a virtualenv.

Running old django app in new virtual environment

I have a django app i was running in python 2.7 and django 1.7.10.However am trying to transition it to django 1.8. I have created a new virtualenv,installed python2.7 and django 1.8 in it and moved the app there.However when i run the server it still reads django 1.7.10.What could be the problem ?
console
enter image description here
You do not need to move application for new virtual environment you just need to activate it probably you did not activate new one. Actually also you do not need a new virtual environment for upgrade. Just pip install -U django==1.8 it will upgrade your django and then make necessary edits.

Using Django on OpenShift

Expanding on this question I am trying to deploy Django on OpenShift but I'm having some problems understanding OpenShift.
I have managed to get as far as setting up a quick app with the git repo https://github.com/openshift/django-example but have the following questions:
Can I develop locally after git cloning to my local? (virtualenv, adding packages)
Packages, what's the deal? local, remote, adding, sycing, virtualenv, git, ...
I came across this line in Nate Aune's PaaS Bakeoff (slide 42) for setup.py and it looks quite useful:
install_requires=open('%s/project.txt' % \
os.environ.get('OPENSHIFT_REPO_DIR', PROJECT_ROOT)).readlines(),
(because I know I can pip freeze > requirments.txt in my virtualenv)
... Is %s/project.txt in wsgi or tthe directory below wsgi? Do I have to set PROJECT_ROOT with some funky os stuff?
EDIT
Basically:
Is it best to ssh into your OpenShift application (lest say you have a dev one) and work there or work off a local copy?
How do you install python packages after you have ssh'ed in to your OpenShift app? (virtualenv)
If you ssh'ed into your OpenShift app do you have to do anything after: creating a project, creating an app (manage.py startapp ...), changing code in your django app
If local is the best option:
How do I use the example locally?
Do I need to setup a virtualenv to work locally?
How do I make sure the python packages django needs are on OpenShift?
How do I add python packages to my OpenShift version (I'm presuming git doesn't do that)
I would suggest developing in a local copy.
In my experience there is no reason to ssh in, unless if you
need to perform one-of operation (migrating databases for example)
The requirements for the openshift app are specified in the setup.py file.
install_requires=['Django>=1.6.0', 'redis>=2.0']
Locally you can of course work in a virtualenv
I was facing a similar situation and found the answer provided by Luis Masuelli to the question posted here very informative. Hope it might help you.

python virtual environment on source control

I have created a python web virtual environment contains all django, pylons related packages. I use the host ubuntu desktop PC at home and I have ubuntu virtual machine running on windows PC laptop.
Both the operating systems are linux only. I will be using the same environment for production that will be ubuntu server.
Is it possible to store the my python virtual environment to the version control and use the same files for ubuntu desktop, laptop ubuntu desktop VM and ubuntu server in production?
You might want to look into virtualenv. This will allow you to set up your working environment, 'freeze' the list of packages that are needed to replicate it, and store that list of requirements in version control so that others can check it out and rebuild the environment with a single step.
You can but you don't really need 'version' control for that. You need to setup your environment. It's a one time job to setup your environment. After that you'll just use it. Why version control it?
If you already have a VM set up, you can export it so that others can copy it and start their own instance with everything installed. VirtualBox and VMWare both support VMDK images, and Xen has its own type of VM images.
That is probably not a solution for setting up servers. I like using Turnkey Linux's appliances for development/staging/deployment servers. They are solid Ubuntu servers preconfigured for a particular application: Django, Rails, LAMP, etc. They come as Ubuntu LiveCD ISO files (for installation) or as virtual machine VMDK packages, and can be deployed to Amazon EC2. You might still have to customize that environment further prior to deploying and testing your code, but it can get you further along than a bare Linux server.

Categories

Resources