擅长:python、mysql、java
<p>您应该给出<code>main_chatbot.py</code>的完整路径。在</p>
<p>最好的方法是使用<a href="http://setuptools.readthedocs.io/en/latest/pkg_resources.html#resource-extraction" rel="nofollow noreferrer">pkg_resources.resource_filename</a>,如下所示:</p>
<pre><code>import pkg_resources
script_path = pkg_resources.resource_filename('chat', 'main_chatbot.py")
</code></pre>
<p>其中<em>chat</em>是包含脚本的包的名称。在</p>
<p>要运行脚本,最好使用与项目可执行文件(virtualenv)相同的Python可执行文件。在</p>
<p>这样做,您可以使用<a href="https://docs.python.org/3/library/sys.html#sys.executable" rel="nofollow noreferrer">sys.executable</a>来获取virtualenv使用的Python路径:</p>
^{pr2}$
<p>最佳做法是将<code>os.system</code>替换为<a href="https://docs.python.org/3.6/library/subprocess.html#subprocess.check_call" rel="nofollow noreferrer">subprocess.check_call</a>,如下所示:</p>
<pre><code>import subprocess
subprocess.check_call([python_path, script_path]
</code></pre>
<p>见<a href="https://docs.python.org/3.6/library/subprocess.html#subprocess-replacements" rel="nofollow noreferrer">Replacing Older Functions with the subprocess Module</a></p>