You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决PyCharm中Django运行时的OSError: [WinError 123]错误

Django运行服务器时WinError 123错误解决&Hello World实现指南

Hey there! I see you're just getting started with Django and ran into this frustrating WinError 123 when trying to run your server. Let's break down what's going on and fix it, then get that Hello World page working.

First, let's recap the error you're seeing (formatted for clarity):

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\W\PycharmProjects\manuproject\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\W\PycharmProjects\manuproject\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\W\PycharmProjects\manuproject\venv\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\W\AppData\Local\Programs\Python\Python37-32\lib\pathlib.py", line 1168, in stat
    return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '<frozen importlib._bootstrap>'

This error usually ties to path issues or version compatibility on Windows. Here are the most likely fixes to try:

  • Check for special characters in your project path
    Windows is picky about paths with spaces, Chinese characters, or symbols like &, #, etc. Move your project to a simpler path like C:\DjangoProjects\manuproject and try running the server again.

  • Fix Python-Django version compatibility
    You're using Python 3.7-32, which doesn't play well with newer Django versions. Uninstall your current Django and install a compatible version:

    pip uninstall django
    pip install django==3.2.18
    

    Version 3.2.x is the last LTS release that fully supports Python 3.7.

  • Reset your virtual environment
    Sometimes virtual environments get glitched out. Close PyCharm entirely, reopen it, reactivate your venv (run venv\Scripts\activate in the terminal), then try python manage.py runserver again.

Once you've fixed the error, let's get that Hello World page up:

  1. Create a new app (Django organizes code into apps)

    python manage.py startapp hello
    
  2. Register the app in settings
    Open your project's settings.py and add 'hello' to the INSTALLED_APPS list:

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'hello',  # Add this line
    ]
    
  3. Write the view function
    Open hello/views.py and replace its content with:

    from django.http import HttpResponse
    
    def index(request):
        return HttpResponse("Hello World")
    
  4. Set up URLs for the app
    Create a new file hello/urls.py and add:

    from django.urls import path
    from . import views
    
    urlpatterns = [
        path('', views.index, name='index'),
    ]
    
  5. Link the app URLs to the project
    Open your project's root urls.py and update it to:

    from django.contrib import admin
    from django.urls import include, path
    
    urlpatterns = [
        path('admin/', admin.site.urls),
        path('', include('hello.urls')),  # Add this line
    ]
    
  6. Run the server again

    python manage.py runserver
    

    Now visit http://127.0.0.1:8000 in your browser, and you should see your "Hello World" message!

内容的提问来源于stack exchange,提问作者Emmanuel Omulo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:11:38