ubuntu /usr/bin/env: python: 没有这样的文件或目录
我更新了内核,之后Ubuntu无法正常工作,PS:我尝试执行“meld”命令,它会报告“/usr/bin/env: python: No such file or directory”, 然后我执行“sudo apt-get install python”并得到结果“python已经是最新版本。”,我应该做什么。
我不擅长linux,你能告诉我如何将我的linux恢复到最后的正确状态,或者正常重新安装python吗?
I update the kernel, after that the Ubuntu doesn't work well, PS: I try to exec "meld" command, it will report that "/usr/bin/env: python: No such file or directory",
then I exec "sudo apt-get install python" and get the result "python is already the newest version.", what should I do for it.
I'm not good at linux, can you tell me how to revert my linux to the last right status, or reinstall the python normally.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
问题场景:
可能的解决方案#1
apt-get install python3
可能的解决方案#2
如果已安装Python 3,请运行以下命令:
whereis python3
然后我们创建一个指向它的符号链接:
sudo ln -s /usr/bin/python3 /usr/bin/python
编辑:大家好,我注意到@mchid发布了一个更好的解决方案低于我的答案:
sudo apt install python-is-python3
。Problem scenario:
Possible Solution #1
apt-get install python3
Possible Solution #2
If Python 3 has been installed, run these commands:
whereis python3
Then we create a symlink to it:
sudo ln -s /usr/bin/python3 /usr/bin/python
EDIT: hi everyone, I noticed that @mchid posted a better solution below my answer:
sudo apt install python-is-python3
.在 Ubuntu 20.04 及更高版本上,有一个包可以解决此问题。运行以下命令:
运行 apt-cache show python-is-python3 了解更多信息。
On Ubuntu 20.04 and newer, there is a package to fix this problem. Run the following commands:
Run
apt-cache show python-is-python3
for more info.我自己暂时被这个错误难住了,我想我应该发布我如何解决我的问题。
我的问题是一个错误:
这对我来说毫无意义。我的问题是我的编辑器已经悄悄地将脚本从 Unix LF 转换为 Windows CR/LF 行终止符。一个相当不幸的结果是“#!/usr/bin/env python”实际上变成了“#!/usr/bin/env python\015”,其中\015是不可见的CR字符... /usr/bin/然后,env 无法找到命令“python\015” - 因此出现文件未找到错误。
将脚本转换为 Unix 行结束约定解决了我的问题...但只是在几分钟的挠头之后。
Having been momentarily stumped by this error myself, I thought I'd post how I fixed my problem.
My problem was an error:
Which made little sense to me. My problem is that my editor had silently converted the script from Unix LF to Windows CR/LF line-termination. A rather unfortunate upshot of this is that "#!/usr/bin/env python" actually became "#!/usr/bin/env python\015" where \015 is the invisible CR character... /usr/bin/env was, then, unable to find a command "python\015" - hence the file-not-found error.
Converting the script to Unix line-ending convention solved my problem... but only after a few minutes' head-scratching.
2022 年 5 月:对于刚刚更新到 Monterey 12.3 的人来说,更新似乎将 python 替换为 python3。下载 python 修复了 Xcode 和 < git 命令行。 请务必阅读下面的两条评论。
May 2022: For anyone who just updated to Monterey 12.3 it appears the update replaces python with python3. Downloading python fixes the issues in Xcode and git command line. Be sure to read the two comments below.
对于在 MacOS 上遇到同样问题并使用自制软件安装了 python3 的人:
For people facing the same issue with MacOS and installed python3 with homebrew:
对于使用 macOS 或 M1 机器(在 12.5 上测试)的用户,符号链接 /usr/bin/python3 将不起作用,因为它是 xcode python3 安装的填充程序。针对 shim 的符号链接只会导致 xcode 安装工具提示安装所需的二进制文件的无限循环。
相反,尝试:
绕过 shim 和 python3 二进制文件的符号链接(从技术上讲,这是指向 xcode 安装的实际 python3 二进制文件的几个符号链接的符号链接,但它已经足够了,因为我们实际上只需要绕过 shim)。
由于这种情况将来可能会发生变化,因此我将包含以下有关如何在 macOS 中填充某些二进制文件的读物:
https://macops.ca/developer-binaries-on-os-x-xcode-select-and-xcrun/
https://randomtechnicalstuff。 blogspot.com/2016/05/os-x-and-xcode-doing-it-apple-way.html
可能有些人感兴趣。
For those with macOS or M1 machines (tested on 12.5) symlinking /usr/bin/python3 will not work because it's a shim to the xcode python3 installation. Symlinking against the shim will just result in an endless cycle of being prompted by the xcode installation tool to install required binaries.
Instead try:
to bypass the shim and symlink to the python3 binary (technically this is a symlink to several symlinks to the actual python3 binary installed by xcode but it's sufficient since we really just need to bypass the shim).
As this might change in the future, I'll include these readings on how certain binaries are shimmed in macOS:
https://macops.ca/developer-binaries-on-os-x-xcode-select-and-xcrun/
https://randomtechnicalstuff.blogspot.com/2016/05/os-x-and-xcode-doing-it-apple-way.html
that may be of interest to some.
只需修改shebang行
来自
#!/usr/bin/env python
到
#!/usr/bin/env python3
,一切顺利。这是自动完成的
sudo apt install python-is-python3
,如 @mchid 回答。为什么会这样:如果你执行
$ python
,它会说Command 'python' not find ...
,但如果你执行$ python3< /code>,它应该可以工作。
Just modify the shebang line
from
#!/usr/bin/env python
to
#!/usr/bin/env python3
, you're good to go.This is automatically done by
sudo apt install python-is-python3
, as @mchid answered.Why this works: If you do
$ python
, it will sayCommand 'python' not found ...
, but if you do$ python3
, it should work.创建符号链接为我解决了这个问题
creating a symbolic link solved the issue for me
这是 Android 构建系统错误的答案
对于 Python 3
如果收到“/usr/bin/env 'python' no such file or directory”错误消息,请使用以下解决方案之一:
如果您的 Ubuntu 20.04.2 LTS 是新安装(相对于升级)的 Linux 版本:
如果使用 Git 版本 2.19 或更高版本,则可以在执行 repo init 时指定 --partial-clone。这利用了 Git 的部分克隆功能,仅在需要时下载 Git 对象,而不是下载所有内容。因为使用部分克隆意味着许多操作必须与服务器通信,所以如果您是开发人员并且使用低延迟网络,请使用以下内容:
您可以参阅以下文档 :
下载源
This answer for android build system error
For Python 3
If you get a "/usr/bin/env 'python' no such file or directory" error message, use one of the following solutions:
If your Ubuntu 20.04.2 LTS is a newly installed (vs. upgraded) Linux version:
f using Git version 2.19 or greater, you can specify --partial-clone when performing repo init. This makes use of Git's partial clone capability to only download Git objects when needed, instead of downloading everything. Because using partial clones means that many operations must communicate with the server, use the following if you're a developer and you're using a network with low latency:
you can see document in
Downloading the Source
如果伙伴的其他建议不起作用,则其他可能的解决方案是将
.py
脚本转换为 UNIX 格式。您可以通过在转换脚本之前安装 dos2unix 来实现这一点。您可以执行以下操作:
安装后,您可以相应地转换脚本:
您可以在此处阅读有关 dos2unix。
--
另外,请尝试在本地运行脚本并查看它是否正常工作,您还需要注意包含 hashbang 。
python3
,如有必要,请使用python
。Additional possible solution if the other suggestions from the mates are not working is to convert the
.py
scripts into UNIX format.You can do so by installing dos2unix, before converting your scripts. You can do with something like this:
Once installed, you can convert your script accordingly:
You can read more here about dos2unix.
--
Separately, do try to run your script locally and see if it's working, you will also need to take note to include the hashbang in your script.
python3
, usepython
if necessary.使用此命令检查 python 是否出现:
或
这些命令应检查它是否已安装并为您提供 Python 路径。
将
python3.x
替换为您使用的版本。你也可以用python2尝试这个配置,只需要修改python3即可。
Check if python appears with this command:
or
These commands should check if it is installed and provide you with the Python paths.
replace
python3.x
with the version you use.You can also try this configuration with python2, you just need to modify python3.