python virtual environment on source control - python

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.

Related

Django project - How to make separate virtual environments for different devices but for the same project (i.e PC and Laptop)

I have a Django project that I'm using for university, and it uses a virtual environment following the tutorial that VSCode provides on Python and Django on their website. As I use multiple devices (PC/Laptop), I share the code with myself via Google Drive. On my PC everything works fine, but when I try to run the local server on my laptop, I get an issue where there is "No python found", which is supposedly due to the pyvenv.cfg having the Python path set to the path where my Python is on my PC, which is obviously not the same as my laptop. I've been unable to find the answer so far, so how can I have 2 separate virtual environments using VSCode where I can easily switch between working on my PC and Laptop?

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.

Using pycharm to debug django application with python3 as docker container within a vagrant instance

I set up an ubuntu vagrant instance as virtual machine and installed docker in it. I also have python as docker container within vagrant instance. Is there anyway to debug django application using pycharm directively with python in this case?
Thanks!
It is possible indeed but I very much doubt you really need to use such a complex setup. Isn't it possible to run Docker on your OS directly?
Anyway, if you are confident. PyCharm at the moment does not "natively" support remote Docker daemon usage, so you have to tweak a bunch of options manually. I wrote a detailed guide in the dedicated ticket in PyCharm's bug tracker: https://youtrack.jetbrains.com/issue/PY-33489 Remote machine in your case is a Vagrant VM.
P.S. Please vote for the PY-33489 ticket if you want such support in PyCharm simplified.

vscode run / debug python in docker instance

I'm using jupyter notebooks to prototype and I write the majority of my code as python packages using vscode and installed as so:
pip install -e .
This works well as I can test rapidly prototype in jupyter but still maintain reusable / testable code by keeping most of the heavy lifting in the package(s)
I'd like to move my python/jupyter environment to docker. Is there any way to configure vscode to work well with a "remote" development environment running in a docker container?
Since May 2019 (version 1.35), VScode remote development feature is present in the stable release. It splits the VScode program in two:
a server part that can be runned on a remote computer, container, or WSL environment
a client part, mainly the GUI, that is runned locally
When properly configured, debugging/linting/... operations will be executed inside the container. To answer your specific question, you can get a debug experience identical the one of an uncontainerized setup.
See here for a quick overview of this feature. You can find a vscode-issued tutorial on how to setup vscode with docker here.
If you expose the Jupyter instance running in the container to your machine, you may be able to specify it as a remote Jupyter server.

Docker container and virtual python environment

I'm getting started working with Docker. I installed Docker Toolbox on Windows 10 and downloaded the desired container. I need full access to container’s filesystem with the ability to add and edit files. Can I transfer the contents of the container into a Virtual Python Environment in Windows filesystem? How to do it?
Transferring files between Windows and Linux might be a little annoying because of different line endings.
Putting that aside, sounds like you are looking to create a Docker based development environment. There are good tutorials online that walk you through setting one up, I would start with one of these
Running a Rails Development Environment in Docker. This one is about Rails, but the principles will be the same. Section 3 specifically talks about about sharing code between your host machine and the Docker container.
How To Work with Docker Data Volumes on Ubuntu 14.04 includes an brief introduction to Docker containers, different use cases for data volumes, and how to get each one working. Sharing Data Between the Host and the Docker Container section talks about what you are trying to do. This example talks about reading log files created inside the container, but the principle is the same for adding/updating files in the container.

Categories

Resources