简体   繁体   中英

No module names django.core, but I can import django from the shell

When I run django in a virtual environment, I get No module named 'django.core' :

(proj)[jenia@li app]$ python manage.py runserver
    Traceback (most recent call last):
      File "manage.py", line 8, in <module>
        from django.core.management import execute_from_command_line
    ImportError: No module named 'django.core'

However, when I run the Python interpreter, and import django, there's no error message:

(proj)[jenia@li app]$ python
Python 3.4.1 (default, May 19 2014, 17:23:49) 
[GCC 4.9.0 20140507 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> 
>>> import django
>>> 

When I import django.core it fails of course.

What am I doing wrong? What could this be related to?

Thanks in advance?

I think you have no django installed at all or you have similar called folder or py-file in current directory.

You can print django.__path__ and I bet it will point to some script, called django.py or package folder django , which is not a django.

You should rename it, so import will look deeper, to python-packages, where real django is located.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM