Reputation: 524
I tried to run a django demo project on a hosted server (Ubuntu 16.04): it worked fine. Then I tried to run the same code on a local machine:
Unhandled exception in thread started by <function wrapper at 0x7fc0c4403f50>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run
autoreload.raise_last_exception()
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 127, in create
import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named about
Therefore I tried to update the django installation (which probably has an older version than the server).
So I tried the pip django update:
sudo pip install -U django
which led to this error:
The directory '/home/lxuser/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/lxuser/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: django in /usr/local/lib/python2.7/dist-packages (1.11.12)
Requirement not upgraded as not directly required: pytz in /usr/local/lib/python2.7/dist-packages (from django) (2018.4)
requests 2.18.4 has requirement certifi>=2017.4.17, but you'll have certifi 0.0.8 which is incompatible.
So I tried this:
sudo -H pip install -U django
and now the error is:
Requirement already up-to-date: django in /usr/local/lib/python2.7/dist-packages (1.11.12)
Requirement not upgraded as not directly required: pytz in /usr/local/lib/python2.7/dist-packages (from django) (2018.4)
requests 2.18.4 has requirement certifi>=2017.4.17, but you'll have certifi 0.0.8 which is incompatible.
So there is an error but the Django installation does not seem to be too old.
So I would like to ask more general:
how can I ensure, that the django versions (and depending libraries) are identical or at least so similiar, that I could run the same project code without code incompatibilies?
How can I even update the versions on two systems (e.g. hosted server and local developpment system) in a synchronized way?
Upvotes: 0
Views: 933
Reputation: 1910
As RishiG said you should create a requirements.txt file which will contains the project dependencies but mostly you should use a virtual environnement. It will allow you to isolate your python version and packages and their version for each of your project.
Upvotes: 1
Reputation: 2830
on the working system, do pip freeze > requirements.txt
copy that file over (I always check one in as part of my repository)
on the new machine, probably in a virtual environment, you can update to those versions with pip install -r requirements.txt
Upvotes: 1