Pydev 和 Django:Shell 找不到某些模块?
我正在 Eclipse 中使用 PyDev 开发 Django 项目。有一段时间,PyDev 的 Django Shell 运行得很好。现在,情况并非如此:
>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
C:\Python26\python.exe 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
>>>
>>> from django.core import management;import mysite.settings as settings;management.setup_environ(settings)
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named mysite.settings
>>>
开发服务器运行得很好。我可能做错了什么?
models 模块也明显缺失:
>>> import mysite.myapp.models
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named mysite.myapp.models
在 PyDev 之外的普通命令行上,shell 工作正常。
为什么会发生这种情况?
I am developing a Django project with PyDev in Eclipse. For a while, PyDev's Django Shell worked great. Now, it doesn't:
>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
C:\Python26\python.exe 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
>>>
>>> from django.core import management;import mysite.settings as settings;management.setup_environ(settings)
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named mysite.settings
>>>
The dev server runs just fine. What could I be doing wrong?
The models module is also conspicuously absent:
>>> import mysite.myapp.models
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named mysite.myapp.models
On the normal command line, outside of PyDev, the shell works fine.
Why could this be happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎是一个简单的路径问题。这个的输出是什么:
我对 PyDev 一无所知,但可能有一个设置可以将路径添加到 PYTHONPATH 设置。如果没有,您可以直接在 shell 中执行:
Seems like a simple path issue. What's the output of this:
I don't know anything about PyDev, but there's probably a setting somewhere to add paths to the PYTHONPATH setting. If not, you can do it directly in the shell:
不久前,我在从 Django 1.3 移动我的项目并将 settings.py 文件放在我的源代码的根目录中,然后将其移动到应用程序中时遇到了类似的问题。
例如,我有以下内容:
rootOfSource/
- 设置.py
- myapp
和我将其更改为:
rootOfSource/
- 我的应用程序
- myapp/settings.py
并且我还将我的设置文件更改为以下内容:
但是,当我调试到 os.eviron 时,我发现 DJANGO_SETTINGS_MODULE 不符合预期,然后我将管理.py 更改为以下内容
:然后允许我从 PyDev 运行。
希望这有帮助。
I had a similar problem to this a while ago while moving my project from Django 1.3 and having the settings.py file at the root of my source and then moving it down into the application.
For example what happened was that I had the following:
rootOfSource/
- settings.py
- myapp
and I changed it to be:
rootOfSource/
- myapp
- myapp/settings.py
and I also changed my settings file to be the following:
However when I debugged into the os.eviron I found that the DJANGO_SETTINGS_MODULE was not as expected, I then changed my manage.py to be the following:
Which then allowed me to run from PyDev.
Hope this helps.
我通过转到项目属性 -> 解决了这个问题PyDev Django 和设置 Django 设置模块。
I fixed this problem by going to the project properties -> PyDev Django and setting the Django settings module.