擅长:python、mysql、java
<p>misakm的回答是不正确的,但在调试过程中帮助了我:问题是<code>__file__</code>在开发计算机上是绝对的,在生产计算机上是相对的。我找到了原因<a href="https://stackoverflow.com/questions/7116889/python-file-attribute-absolute-or-relative#answer-7116925">here</a>:</p>
<blockquote>
<p>If you load a module in the current directory, and the current
directory isn't in sys.path, you'll get an absolute path.</p>
<p>If you load a module in the current directory, and the current
directory is in sys.path, you'll get a relative path.</p>
</blockquote>
<p>解决方案是这样添加<code>abspath</code>:</p>
<pre><code>os.path.join(os.path.dirname(os.path.abspath(__file__)), 'favicon.ico')
</code></pre>
<p>罪魁祸首是几周前对Windows环境进行的一些维护,它改变了路径。在</p>