回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我想在我的Windows10机器上使用GitHub中的一些代码。我经常遇到的错误是:</p>
<pre><code>AttributeError: module 'os' has no attribute 'fork'
</code></pre>
<p>我查了一下,发现Windows不支持<code>os.fork()</code>调用,所以我尝试寻找在Windows机器上获取bash的方法(将来可能需要bash来编写其他脚本)。我发现了Windows Linux子系统,它听起来非常适合这个。我安装了WLS1,并从微软商店获得了Ubuntu。Bash看起来像预期的那样工作,但是这个脚本仍然在Bash中抛出相同的错误</p>
<p>几年前我发现了一个类似的问题。公认的答案是建议在虚拟机上运行Linux应用程序,我认为这正是我正在做的(对吗?)。有人知道我如何让这个脚本工作吗?(顺便说一句,我知道它可以工作,因为我以前在工作时的Linux机器上运行过它。)</p>
<hr/>
<p>编辑:这可能是另一个问题的症状</p>
<p>我认为这意味着Ubuntu WSL1使用的是python的Linux路径:</p>
<p>在Powershell中:<code>Get-Command python</code>给我<code>C:\Users\myname\AppData\Local\Microsoft...</code></p>
<p>在Ubuntu中:<code>which python</code>给我<code>/usr/bin/python3</code></p>
<p></p>
<p>在Powershell中,如果我尝试使用<code>wellmap .\wellmap-text.toml</code>读取.toml文件,就会出现“not In Path”错误(在我尝试设置机器时,我已经看到了很多错误,我不知道如何正确地将内容添加到路径中,或者这样做可能会破坏某些内容)</p>
<pre><code>wellmap : The term 'wellmap' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ wellmap .\wellmap-text.toml
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (wellmap:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
</code></pre>
<p>在Ubuntu WSL上,运行<code>wellmap ./wellmap-text.toml</code>会给我一个<code>command not found</code>错误</p>
<p></p>
<p>因为我知道wellmap.exe的路径,所以我尝试直接给Powershell和Ubuntu这个路径,并且是超显式的。这就是我得到<code>module 'os' has no attribute 'fork'</code>错误的地方</p>
<p>在Powershell中:</p>
<pre><code>& “C:\Users\myname\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts\wellmap.exe” \Users\myname\Desktop\wellmap-text.toml
</code></pre>
<p>这个错误是:</p>
<blockquote>
<p>Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in <em>run_code
exec(code, run_globals)
File "C:\Users\myname\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts\wellmap.exe_<em>main</em></em>.py", line 7, in
File "C:\Users\myname\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\wellmap\plot.py", line 101, in main
if os.fork() != 0:
AttributeError: module 'os' has no attribute 'fork'</p>
</blockquote>
<p>在Ubuntu中:</p>
<pre><code>/mnt/c/Users/myname/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/local-packages/Python39/Scripts/wellmap.exe /mnt/c/Users/myname/Desktop/wellmap-test.toml
</code></pre>
<p>还有同样的错误:</p>
<blockquote>
<p>Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\runpy.py", lin
e 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.496.0_x64__qbz5n2kfra8p0\lib\runpy.py", lin
e 87, in <em>run_code
exec(code, run_globals)
File "C:\Users\myname\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-package
s\Python39\Scripts\wellmap.exe_<em>main</em></em>.py", line 7, in
File "C:\Users\myname\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-package
s\Python39\site-packages\wellmap\plot.py", line 101, in main
if os.fork() != 0:
AttributeError: module 'os' has no attribute 'fork'</p>
</blockquote>