python - pip已安装成功Django,import时依然提示ImportError: No module named Django?
大家讲道理
大家讲道理 2017-04-18 09:55:33
0
4
751

此问题出现在,学习Django时pip安装好Django后,import Django依然报错,下面为问题截图:
pip安装成功后,命令行执行pip freeze,显示如下:

进入python环境,type import Django,报错,信息如下:

经查询,python下typehelp('modules'),显示可import模块并没有Django:

又经查询,怀疑可能是pip安装的python版本与当前版本不匹配,于是查看:

发现版本匹配,进入到site-packages目录,显示模块,如下:

pip 安装的模块都有以上问题出现。
奇怪的是,PyCharm中import Django,cocos 等,均可正常运行,但命令行无法import模块;同样,命令行通过python 运行 *.py 文件时,依然报错,怀疑变量问题...


最近在自学Python中,对于出现的一些问题希望弄透彻,打下好基础。
对于以上问题,最近找了好多资料,但好像都没有太针对此问题的解决,第一次在segmentfault提问,希望得到Python小伙伴的帮助,望指教

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(4)
刘奇

This problem has been solved. It is mainly about the module search path. Configure the PYTHONPATH environment variable under Windows. Generally, add C:Python27Lib; C:Python27Libsite-packages. After saving, print the sys.path path in interactive mode to display There is an error. It may be related to the difference between Windows and Linux paths. Then I added it manually through sys.path.append('C:Python27Lib;C:Python27Libsite-packages') in interactive mode, and then the import module can be used normally, but This method is only temporary and will be reset after exiting the command line.

I still have a question about the sys.path path problem. The results printed in pycharm and the command line are inconsistent. I think it may be because I use babun. I probably don’t understand the use of babun too much

巴扎黑

Isn’t it lowercase django?

伊谢尔伦

Although mine was not solved using this method, the poster gave me a good solution. Thanks,
My final solution is:

洪涛

I just started learning and encountered the same problem. I upgraded python from 2.7 to 3.5 for centos7 and installed pip. However, the django installed by pip was placed under 2.7, which caused python to be unable to import django and also reported module errors. I haven't solved it yet, please give me some guidance.

I executed python -c "import django; print(django.get_version())" and it suddenly worked. I was confused.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template