无法导入django

时间:2015-05-01 06:42:50

标签: django windows-8.1 pip

我安装了python 2.7,然后通过pip安装了django。

C:\WINDOWS\system32>pip install Django
You are using pip version 6.0.8, however version 6.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting Django
  Downloading Django-1.8-py2.py3-none-any.whl (6.2MB)
    100% |################################| 6.2MB 79kB/s
Installing collected packages: Django

Successfully installed Django-1.8

C:\WINDOWS\system32>

当我尝试导入django时,现在什么都不可能。

>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django
>>>

可以做些什么呢?我尝试重新安装pip然后突然再也没有可能了。

C:\Users\cleanup\Downloads>python get-pip.py
Collecting pip
  Downloading pip-6.1.1-py2.py3-none-any.whl (1.1MB)
    100% |################################| 1.1MB 335kB/s
Installing collected packages: pip
  Found existing installation: pip 1.5.4
    Uninstalling pip-1.5.4:
      Successfully uninstalled pip-1.5.4
Successfully installed pip-1.5.6

C:\Users\cleanup\Downloads>pip list
'pip' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\cleanup\Downloads>python pip list
python: can't open file 'pip': [Errno 2] No such file or directory

C:\Users\cleanup\Downloads>

2 个答案:

答案 0 :(得分:1)

该错误表示Python无法找到pip.py。请确保pip的目录位于搜索路径中。

要实现这一点,您应该转到“高级系统属性”&gt; “环境变量”并将%PYTHONHOME%\Scripts添加到PATH。如果您没有PYTHONHOME,则应创建变量并将其设置为Python主目录。在大多数情况下,它是C:\Program Files (x86)\Python

答案 1 :(得分:-2)

由于您已成功安装Python,因此Django官方网站上有一个关于how to install Django on Windows的有用文档。我认为你可以参考一些很好的资源。

顺便说一下,在Windows上,pip位于C:\[pythondir]\scipts。不要忘记将pip路径放到系统路径中或只使用bat脚本:

@C:\[pythondir]/scripts\pip.exe %*