简体   繁体   English

ImportError:没有名为django的模块,sys.path很好

[英]ImportError: No module named django, sys.path fine

I'm trying to configure Django with 我正在尝试使用配置Django

python manage.py shell

And I get the error: 我得到错误:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
    django.setup()
  File "/usr/lib64/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/lib64/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/lib64/python2.7/site-packages/django/apps/config.py", line 123, in create
    import_module(entry)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named django

I've seen a lot of questions about this error, and most of them seem to be centered on the fact that django's path is not included in python's sys.path. 我已经看到了很多有关此错误的问题,而且大多数问题似乎都集中在Django的路径未包含在python的sys.path中这一事实上。 Mine is, however. 但是我的是。 When I run 当我跑步

sudo pip install django

I get 我懂了

Requirement already satisfied: django in /usr/lib64/python2.7/site-packages

And the output for my sys.path is 我sys.path的输出是

['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages']

So the path is absolutely there. 因此,路径绝对存在。 What are my options here? 我在这里有什么选择? This is a remote interpreter using SSH from Pycharm, and it's seriously delaying my work. 这是使用Pycharm的SSH的远程解释器,严重延迟了我的工作。

If which python , when run by the normal user, returns ~/bin/python , then this is a different Python from the one run by the superuser, which, according to what you say, is /bin/python . 如果由普通用户运行的which python返回~/bin/python ,则这与超级用户运行的Python不同,根据您的说法,超级用户运行的是/bin/python sudo pip install django runs as the superuser and installs Django in the system's Python environment. sudo pip install django以超级用户身份运行,并将Django安装在系统的Python环境中。 When, afterwards, you execute python manage.py shell , it runs another Python, and that other Python's environment apparently doesn't have Django installed. 之后,当您执行python manage.py shell ,它将运行另一个Python,并且该其他Python的环境显然未安装Django。

If you run pip install django without the sudo it might work, but since you have superuser permission on that machine it would be better to get rid of the Python installation that you have in the normal user's home directory, and make sure your system has only one Python installation until you really know what you are doing. 如果您在不使用sudo情况下运行pip install django可能会起作用,但是由于您在该计算机上具有超级用户权限,因此最好摆脱普通用户主目录中的Python安装,并确保系统仅具有一次安装Python,直到您真正知道自己在做什么。 Otherwise you will be confused whether you use virtualenv or not. 否则,无论是否使用virtualenv,您都会感到困惑。

Edit: I disagree with many comments that tell you to use virtualenv. 编辑:我不同意许多告诉您使用virtualenv的评论。 You are confused enough without it. 没有它,您很困惑。 Let's simplify the problem first. 让我们首先简化问题。 Remove all virtualenvs you have created (you do this by deleting the directories) and forget everything about virtualenv. 删除所有已创建的virtualenv(通过删除目录来执行此操作),然后忘记有关virtualenv的所有信息。 Logout and login again (this will ensure the virtualenvs are deactivated). 注销并再次登录(这将确保virtualenvs被停用)。 Don't modify your manage.py , it's fine as it was originally. 不要修改您的manage.py ,它可以像原来一样好。 Install Django system-wide with sudo pip install django , then try to run your Django project with python manage.py shell . 使用sudo pip install django整个系统范围内sudo pip install django ,然后尝试使用python manage.py shell运行Django项目。 Only after you get it working and you start having a grip on the system go on to start playing with virtualenv. 只有当它开始工作并且开始掌握系统后,才可以开始使用virtualenv。 Virtualenv is great, but everything in its time. Virtualenv很棒,但是一切都在它的时代。 ( virtualenv demystified is an introduction to virtualenv written by me.) (被揭秘的virtualenv是我写的virtualenv的简介。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django部署:ImportError:无法导入设置“ settings.py”(在sys.path上吗?):没有名为settings.py的模块 - Django Deployment: ImportError: Could not import settings 'settings.py' (Is it on sys.path?): No module named settings.py 当模块位于sys.path中时,Python ImportError - Python ImportError when module is in sys.path Django ImportError:无法导入设置“ mysite.settings.local”(在sys.path上吗?):没有名为settings.local的模块 - Django ImportError: Could not import settings 'mysite.settings.local' (Is it on sys.path?): No module named settings.local 没有名为error python的模块,是否在sys.path上? - no module named error python, is it on sys.path? ImportError:无法导入设置&#39;mysite.settings&#39;(是否在sys.path上?):没有名为mysite.settings的模块 - ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings ImportError:无法导入设置“ settings.py”(在sys.path上吗?):没有名为py的模块 - ImportError: Could not import settings 'settings.py' (Is it on sys.path?): No module named py ImportError:无法导入设置“ wequest.settings”(在sys.path上吗?):没有名为wequest.settings的模块 - ImportError: Could not import settings 'wequest.settings' (Is it on sys.path?): No module named wequest.settings ImportError:无法导入设置“ company.foo.settings”(在sys.path上吗?):没有名为foo.settings的模块 - ImportError: Could not import settings 'company.foo.settings' (Is it on sys.path?): No module named foo.settings ImportError:无法导入设置“ LJ.settings”(在sys.path上吗?):没有名为代码的模块 - ImportError: Could not import settings 'LJ.settings' (Is it on sys.path?): No module named code Pyinstaller - ImportError:模块'pythoncom'不在冻结的sys.path中 - Pyinstaller - ImportError: Module 'pythoncom' isn't in frozen sys.path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM