Should I need separate virtual environments for every separate Django project - python

Does every Django project needs a separate virtual environment? Can't I use one of my exciting virtual env ? If I can't, then what's the problem?

Related

How to add virtual environment in an existing Django rest project

I have made a Django rest project I want to add virtual environment to it
https://github.com/iamahmedshahh/djangowallet
This is the structure of my project which is pretty much the default structure when creating a project from command line.

Must i install django every time am starting a project in pycharm

i am just starting a new project on my pycharm i start a new project and run my server but am getting this error message couldn't import django, Must i install django for every project am creating?
If you are using virtual environment for every new project then you need to install django each time. Other wise you can use single virtual environment for all the project. It depends on you how you prefer. But I highly recommend you to use separate virtual environment for new project.

Should I activate my Python virtual environment before running my app in upstart?

I am working through the process of installing and configuring the Superset application. (A Flask app that allows real-time slicing and analysis of business data.)
When it comes to the Python virtual environment, I have read a number of articles and how-to guides and understand the concept of how it allows you to install packages into the virtual environment to keep things neatly contained for my application.
Now that I am preparing this application for (internal) production use, do I need to be activating the virtual environment before launching gunicorn in my upstart script? Or is the virtual environment more just for development and installing/updating packages for my application? (In which case I can just launch gunicorn without the extra step of activating the virtualenv.)
You should activate a virtualenv on the production server the same way as you do on the development machine. It allows you to run multiple Python applications on the same machine in a controlled environment. No need to worry that an update of packages in one virtualenv will cause an issue in the other one.
If I may suggest something. I really enjoy using virtualenvwrapper to simplify the use of virtualenvs even more. It allows you to define hooks, e.g.: preactivate, postactivate, predeactivate and postdeactivate using the scripts in $VIRTUAL_ENV/bin/. It's a good place for setting up environmental variables that your Python application can utilize.
And a good and simple tool for process control is supervisord.

Why do I need to create a virtual environment for my public Django application?

I've been running my Django project (website) in my local virtual environment. However I now want to go live and make the website public - so I've created my remote server on Digital Ocean, and have been following it's tutorial on settings up Django. However I've reached this point in the tutorial where it says to create a virtual environment. I thought virtual environments were only used for testing your application offline? Why do I need a virtual environment for my application running on a remote server?
I'm not really familiar with Digital Ocean, but creating a virtualenv should not be strictly required.
It is still a good idea and I'd recommend doing it though.
It will prevent packages required for your application that you install to your virtual environment from messing up other Python applications requirements.
For example, let's say your application requires coolpackage 0.9.12, and another application requires coolpackage 1.1.6. If there are breaking changes going from 0.9.12 to 1.1.6, installing coolpackage 1.1.6 will break your first application.
Also, keep in mind that some functionality of your operating system might require specific versions of Python packages (which might even have been installed by some other means than pip) that you could break in this way.

python conda deployment on server

Let say I have two projects that I develop on my personal machine. I use conda to manage my python dependencies. I created environments to manage these projects. When I'm done with the dev, I want to export them to a remote machine that will run regularly, in the same time, these two projects. How should I manage this deployment ?
After some researches, I came up with this:
clone your environments as described on conda's doc.
export your environment file on the server along with your project.
import the environment on the server's conda.
create a bash script like that
#!/bin/bash
source activate my_environment
python ~/my_project/src/code.py
set up cron as usual calling this previous bash script

Categories