The project on django uses modules that are installed in virtual space (virtualenv). Using pyCharm and setting up virtual space (I checked its work when installing new modules), I start the server, and it reports

(myvenv)root@localhost:/home/Project/mysite# sudo python manage.py syncdb Traceback (most recent call last): File "manage.py", line 11, 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 south 

I (myvenv)root@localhost:/home/Project/mysite# pip list

among other things I see:

 South (1.0.2) 

Here in PyCharm: enter image description here

Why then shows ImportError: No module named south

    2 answers 2

    sudo does not transfer environment variables by default, so your virtualenv is not activated as root.

    To run the correct python command, you can specify the full path to it:

     $ /home/Project/anyvenv/bin/python ... 

    If in your virtualenv any additional environment variables are set when activated, you can explicitly activate:

     $ . /home/Project/anyvenv/bin/activate && python ... 

    It is probably not worth running the django manage.py migrate command (replacing an obsolete syncdb command) as root.

    • Thanks for the answer, but it's very hard for me to understand you (I have little experience with Debian and django). My understanding would be facilitated by examples specifically on my project. - EmptyMan
    • @EmptyMan: the answer is not specific to either debian or django (it is applicable to any Unix system with sudo and python). If you do not understand the words: "environment variables", "run a command", "path", root, then you should read the introductory guide to Unix to get acquainted with the basics. - jfs
    • I have virtualenv here /home/Project/anyvenv/bin/activate then how can I use your answer to start the python command: python manage.py syncdb ? - EmptyMan
    • I used your answer and added, it turned out like this: # . /home/Project/anyvenv/bin/activate && python manage.py syncdb # . /home/Project/anyvenv/bin/activate && python manage.py syncdb - EmptyMan

    while solving this problem by manually starting the python application from the command line, and not through the PyCharm panel