0

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?

Mike75
  • 504
  • 3
  • 18

2 Answers2

1

Use a requirements file

  1. on the working system, do pip freeze > requirements.txt

  2. copy that file over (I always check one in as part of my repository)

  3. on the new machine, probably in a virtual environment, you can update to those versions with pip install -r requirements.txt

RishiG
  • 2,790
  • 1
  • 14
  • 27
  • Fine. Thank you! – Mike75 Apr 28 '18 at 11:49
  • tried to install requirements with pip: `Could not find a version that satisfies the requirement python-apt==1.1.0b1 (from -r requirements.txt (line 3)) (from versions: 0.0.0, 0.7.8) No matching distribution found for python-apt==1.1.0b1 (from -r requirements.txt` – Mike75 Apr 28 '18 at 20:43
  • Sorry, I'm not familiar with that package. Looks like it's a beta version which might not have made it into pip yet, but that's pretty surprising. Usually you can get pre-release versions with `pip install --pre`. If you really need that version of this package, it might per worth posting a new question. – RishiG Apr 29 '18 at 04:20
  • Thank you. I'm not sure what happened here: all I did was to start a system with Ubuntu 16.04. and then three standard commands: `sudo apt-get install python-pip` `sudo pip install --upgrade pip` `sudo pip install Django==1.11` The versions seem to be typical, so I don't quite udnerstand why the requirements are that special in the end. I'll have a further look at virualenv, maybe this helps. – Mike75 Apr 29 '18 at 18:18
1

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.

May.D
  • 1,832
  • 1
  • 18
  • 34