Manage.py - ImportError: no module named django

I just ported a working django application from a Windows system to ubuntu, just copying all the files to /var/www/some/dir/djangoApp. But now that you are doing

python manage.py runserver 8080

I get an error message:

ImportError: no module named django

I already installed the new version of django with python setup.py installin /usr/local/lib/python2.7/dist-packages/django/and added the path to PYTHONPATH.

The linux system is not supported by me and has many versions of python.

a call >>> import djangoin the shell does not raise ImportError.

I am very confused. Please help me!

Here's the trace from the console:

Traceback (most recent call last):
  File "manage.py", line 13, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 280, in execute
    translation.activate('en-us')
  File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py", line 130, in activate
    return _trans.activate(language)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 188, in activate
    _active.value = translation(language)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 177, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 159, in _fetch
    app = import_module(appname)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
ImportError: No module named django
+4
source share
3 answers

Since you just switched to UNIX, I suggest that you also transfer to the best practices on such a platform.

  • PIP

    sudo apt-get install python-pip

  • virtualenv, python . django .

    sudo pip install virtualenv

  • , . myvirtualenvironment bin .

    virtualenv myvirtualenvironment --no-site-packages

  • , , script, /myvirtualenvironment/bin/

    source myvirtualenvironment/bin/activate

  • django .

    pip install django pip install django==1.6 , . , ​​ .

  • Django /myvirtualenvironment/ runerver.

+8

.pyc , . Django pip.

sudo pip install django

requirements.txt( Windows)

pip freeze > requirements.txt

virutalenv

mkvirtualenv  myapp
pip install -r requirements.txt 
+2

I got to this page after I received the same error (on a site that I have been actively developing for several months). @Asaji's answer reminded me that I forgot to start the virtual environment.

After starting my Virtual Env . Scripts/activate . Scripts/activateworked fine!

0
source

Source: https://habr.com/ru/post/1543380/


All Articles