PyCharm无法使用Django新建项目:'django-admin.py'不是内部或外部命令

稍有意识的程序员一定想到是Path环境变量的问题

没错,在调用django-admin.py startapp bolg的时候程序出错,前提是settings.py和urls.py都配置好了
运行
Traceback (most recent call last):
  File "C:/Users/lifei/PycharmProjects/csvt01/manage.py", line 10, in 
    execute_from_command_line(sys.argv)
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 327, in execute
    django.setup()
  File "C:\Python34\lib\site-packages\django\__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Python34\lib\site-packages\django\apps\registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "C:\Python34\lib\site-packages\django\apps\config.py", line 90, in create
    module = import_module(entry)
  File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 2254, in _gcd_import
  File "", line 2237, in _find_and_load
  File "", line 2224, in _find_and_load_unlocked
ImportError: No module named 'blog'
很简单log说压根就没有blog模块,为什么呢,因为命令根本没起作用


解决办法很简单:我的电脑设置环境变量,找到你的Python安装路径下的site-packages/django/bin(例如:D:\Python34\Lib\site-packages\django\bin),把这个路径加入系统环境变path中。
再在PyCharm自定带Terminal中执行 就发现 项目中 多出一个blog的目录,到这里就大功告成了

你可能感兴趣的:(Python)