Forums

I cannot run manage.py because of import error

I wanted to test somethinng and run mange.py through Bash console but I got error:

    20:18 ~/My-stuff/mysite (master)$ python manage.py
Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_from_command_line(sys.argv)
  File "/home/dzikuss98/My-stuff/myvenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command
_line
    utility.execute()
  File "/home/dzikuss98/My-stuff/myvenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 316, in execute
    settings.INSTALLED_APPS
  File "/home/dzikuss98/My-stuff/myvenv/lib/python3.5/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/home/dzikuss98/My-stuff/myvenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/dzikuss98/My-stuff/myvenv/lib/python3.5/site-packages/django/conf/__init__.py", line 97, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named mysite.settings
20:20 ~/My-stuff/mysite (master)$ ``

this is my manage.py file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#!/usr/bin/env python
import os
import sys

sys.path.insert(1,'/home/dzikuss98/My-stuff/myvenv/lib/python3.5/site-packages')
path = '/home/dzikuss98/My-stuff/mysite'  # use your own username here
if path not in sys.path:
    sys.path.append(path)
if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

I copied this from WSGI file: path = '/home/dzikuss98/My-stuff/mysite' # use your own username here if path not in sys.path: sys.path.append(path)

I thought it's gonna work bu not

Normally you shouldn't need to change your manage.py file -- everything in there is standard boilerplate.

This help page, although it is targeted at people trying to debug problems with their websites rather than manage.py, should give you some useful background information that might help you work out what's going on.

yes, I already went through that page but nothing helped

I am not sure where this ImportError: No module named mysite.settings comes from

Your traceback somehow has both python2.7 and python3.5 in it. Maybe run ./manage.py or python3.5 manage.py to specify the python version? I'm assuming you are not using a virtualenv?

thanks I was able to run correctly with this: python3.5 manage.py