Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transfer a django project to another machine

This is a beginner question, but I haven't found the answer. I'd like to transfer my django project from virtual machine with Ubuntu 18.04 to another virtual machine with Ubuntu 18.04.

This is the example directory structure

pd_videowebapp/
├── db.sqlite3
├── env
│   ├── bin
│   ├── lib
│   └── pyvenv.cfg
├── manage.py
├── media
│   ├── images
│   └── video
├── mysite
│   ├── core
│   ├── __init__.py
│   ├── __pycache__
│   ├── settings.py
│   ├── static
│   ├── templates
│   ├── urls.py
│   └── wsgi.py
├── Pipfile
├── requirements.txt
└── static
    ├── admin
    ├── style2.css
    └── style3.css

In env directory there is a Python virtual environment.

Before I transfer it I would run

$ pip freeze > requirements.txt

Then I would zip all the directory structure except for db.sqlite3 and media directory.

Then unzip it on another VM.

Then copy the db.sqlite3 and media directory to the right place.

Then create a virtual environment on another VM.

Then run

$ pip install -r requirements.txt

Or should I rather copy the whole project with env directory in the beginning? What is better? Did I omit something? Or is there a better approach?

like image 471
xralf Avatar asked Dec 29 '25 16:12

xralf


1 Answers

Or should I rather copy the whole project with env directory in the beginning? What is better? Did I omit something? Or is there a better approach?

It is better not to copy the env directory. Exclude this directory.

There are lots of ways to do this. I suggest you use Git. For this:

  1. create a git repository from current project
  2. use proper .gitignore file to ignore env directory and other environment-related stuff:
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Other stuff
  1. clone the project from other VM and config the virtual environment in this VM

Simpler Way:

  1. zip your whole project while excluding env directory and other ignored stuffs manually.

  2. move the zip file to other VM and config the virtual environment in this VM

like image 64
Hamid Rasti Avatar answered Jan 01 '26 12:01

Hamid Rasti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!