簡體   English   中英

在Windows 8.1上使用Django的manage.py runserver出錯

[英]Error in manage.py runserver with Django on windows 8.1

我無法在任何地方找到這個exitcode,但希望你們中的一個可以幫助我或讓我知道這是否是python / Django中的錯誤。

無論如何,首先是這里的堆棧跟蹤:

    Traceback (most recent call last):
  File "C:\Sitezooi\SiteTest\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Program Files\Python\lib\site-packages\django\core\management\__init_
_.py", line 385, in execute_from_command_line
    utility.execute()
  File "C:\Program Files\Python\lib\site-packages\django\core\management\__init_
_.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Program Files\Python\lib\site-packages\django\core\management\base.py
", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Program Files\Python\lib\site-packages\django\core\management\base.py
", line 338, in execute
    output = self.handle(*args, **options)
  File "C:\Program Files\Python\lib\site-packages\django\core\management\command
s\runserver.py", line 83, in handle
    self.run(*args, **options)
  File "C:\Program Files\Python\lib\site-packages\django\core\management\command
s\runserver.py", line 92, in run
    autoreload.main(self.inner_run, args, options)
  File "C:\Program Files\Python\lib\site-packages\django\utils\autoreload.py", l
ine 322, in main
    reloader(wrapped_main_func, args, kwargs)
  File "C:\Program Files\Python\lib\site-packages\django\utils\autoreload.py", l
ine 293, in python_reloader
    exit_code = restart_with_reloader()
  File "C:\Program Files\Python\lib\site-packages\django\utils\autoreload.py", l
ine 279, in restart_with_reloader
    exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: inval
id character

請忽略這個奇怪的文件路徑,我甚至只是嘗試將它直接放在C:\\上。

這里有另一個類似的Stackoverflow問題: 使用編譯函數時的UnicodeEncodeError,但它不像我使用的文件路徑使用任何非英文字符。 我在那里嘗試了幾種解決方案,但它們沒有用。

運行python 3.4.1,之前在2.7.x中測試過,也沒有用。 在linux(Ubuntu)上運行良好。

django項目沒有什么特別之處,因為它只是空的startproject項目。

我遇到了同樣的問題,我找到了解決方案。 從我搜索到的內容也發生在Windows 7和8中。

如果您想更詳細地了解我是如何解決的,請查看我在Django論壇中提交的票證: Windows上的manage.py runserver出錯(7/8 / 8.1)

現在解決錯誤打開這個文件C:\\ Program Files \\ Python \\ lib \\ site-packages \\ django \\ utils \\ autoreload.py (我使用你的代碼作為參考)並在你的錯誤之前添加這行代碼(第279行):

new_environ['PATH'] = os.path.abspath(new_environ['PATH'].replace('\u202a', ''))

你現在的功能應該是這樣的:

def restart_with_reloader():
    while True:
        args = [sys.executable] + ['-W%s' % o for o in sys.warnoptions] + sys.argv
        if sys.platform == "win32":
            args = ['"%s"' % arg for arg in args]
        new_environ = os.environ.copy()
        new_environ["RUN_MAIN"] = 'true'
        new_environ['PATH'] = os.path.abspath(new_environ['PATH'].replace('\u202a', ''))
        exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
        if exit_code != 3:
            return exit_code

現在再次嘗試使用manage.py runserver。 我希望這能解決你的問題,不要覺得你是孤身一人。

在我的情況下,它與PATH無關,似乎有一些非英文字符的CHROME_RESTART環境設置。 new_environ彈出它就可以了:

def restart_with_reloader():
    while True:
        args = [sys.executable] + ['-W%s' % o for o in sys.warnoptions] + sys.argv
        if sys.platform == "win32":
            args = ['"%s"' % arg for arg in args]
        new_environ = os.environ.copy()
        new_environ["RUN_MAIN"] = 'true'

        # This will prevent UnicodeEncodeError
        new_environ.pop("CHROME_RESTART", None)

        exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
        if exit_code != 3:
            return exit_code

我試過這個

new_environ['PATH'] = os.path.abspath(new_environ['PATH'].replace('\u202a', ''))

但它不起作用。

我的解決方案是

new_environ['PATH'] = os.path.abspath(new_environ['PATH'].encode('ascii', 'replace'))

希望它能幫到你!

UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1:invalid character

我在Windows 7上遇到了同樣的問題

$ python manage.py runserver

萬一有人像我一樣擁有西里爾語的計算機名稱,這正是造成編碼問題的原因。 所以解決方案是僅使用拉丁字母符號重命名您的計算機。

我有同樣的問題。
原因是環境變量條目中的非拉丁字符。
在我的情況下,它是一些文件夾的cyrilic名稱,而我的Windows最初是英文版。
所以它有沖突。 刪除后 - 一切正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM