Makemessages对设置抛出ImportError

2024-05-08 04:05:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一些Django/Python应用程序的帮助。
我尝试了很多天来运行django admin的“makemessages”命令,但没有成功。。。

一些解释:
我的项目目录树:

MyProject
   MyProject
      locale
      settings.py
      wsgi.py
      ...
   App1
      models.py
      views.py
      ...

当我想跑的时候

^{pr2}$

我有个错误:

(env33) PS C:\DEV\myproject> python ..\env33\Scripts\django-admin.py makemessages --all -v 3
Traceback (most recent call last):
  File "C:\DEV\env33\lib\site-packages\django\conf\__init__.py", line 132, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\DEV\env33\lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named 'myproject'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "..\env33\Scripts\django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "C:\DEV\env33\lib\site-packages\django\core\management\__init__.py", line 453, in execute_from_comman
    utility.execute()
  File "C:\DEV\env33\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\DEV\env33\lib\site-packages\django\core\management\__init__.py", line 263, in fetch_command
    app_name = get_commands()[subcommand]
  File "C:\DEV\env33\lib\site-packages\django\core\management\__init__.py", line 109, in get_commands
    apps = settings.INSTALLED_APPS
  File "C:\DEV\env33\lib\site-packages\django\conf\__init__.py", line 53, in __getattr__
    self._setup(name)
  File "C:\DEV\env33\lib\site-packages\django\conf\__init__.py", line 48, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\DEV\env33\lib\site-packages\django\conf\__init__.py", line 134, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'myproject.settings' (Is it on sys.path?): No module named 'myproject'

但是:

(env33) PS C:\DEV\myproject> Get-ChildItem Env:DJANGO_SETTINGS_MODULE

Name                    Value
----                    -----
DJANGO_SETTINGS_MODULE          myproject.settings

“C:\dev\myproject”在“PATH”环境变量中。我尝试运行Django shell:

(env33) PS C:\DEV\myproject>python .\manage.py shell
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import myproject.settings
>>> myproject.settings.DEBUG
True
>>>

一切似乎都很好,runserver也在工作。如你所见,我在一家虚拟公司工作,这可能是个问题?
我也尝试从MyProject子目录运行makemessages,但是我得到了相同的错误。
我不明白。我搜索了stackoverflow和许多网站,但都没有找到一个有效的解决方案。
我在Windows上使用django1.6,python3.3。在


谢谢你的帮助。在

谨致问候, M、 乔科


Tags: djangoinpydevimportsettingsinitlib