Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pydev and Django: Shell not finding certain modules?

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?

like image 413
Nick Heiner Avatar asked Apr 14 '26 01:04

Nick Heiner


1 Answers

Seems like a simple path issue. What's the output of this:

import sys; print sys.path

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:

sys.path.insert(0, '/path/to/directory/containing/mysite/')
like image 129
Daniel Roseman Avatar answered Apr 16 '26 13:04

Daniel Roseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!