Oli*_*çon 3 python permissions pycharm python-3.x python-os
我在 Pop_OS 下使用PyCharm 2020.2.3和Python 3.8.6!20.10(您可能可以像我使用Ubuntu 20.10一样),它无法在/usr/bin或中查看文件/usr/lib。
这是我尝试触摸二进制文件的示例/usr/lib/firefox/firefox。
# main.py
import os
print(os.path.exists('/usr/lib'))
print(os.path.exists('/usr/lib/firefox'))
print(open('/usr/lib/firefox/firefox', 'r'))
Run Code Online (Sandbox Code Playgroud)
从命令行,这是有效的:
>>> python main.py
True
True
<_io.TextIOWrapper name='/usr/lib/firefox/firefox' mode='r' encoding='UTF-8'>
Run Code Online (Sandbox Code Playgroud)
但是当我在 PyCharm 中运行它时,它失败了,如下所示:
True # Can see /usr/lib
False # Cannot see /usr/lib/firefox
Traceback (most recent call last):
File ..., line 5, in <module>
print(open('/usr/lib/firefox/firefox', 'r'))
FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/firefox/firefox'
Run Code Online (Sandbox Code Playgroud)
以下是以下权限usr/bin/firefox:
>>> ls -ld firefox
drwxr-xr-x 8 root root 4096 Oct 26 10:22 firefox
Run Code Online (Sandbox Code Playgroud)
关于类似问题有很多问题,但大多数最终都建议与所需的特定文件相关的解决方法。
似乎存在某种权限问题,我想解决这个问题,而不必依赖解决方法。
一个多月后,我在 intellij-support 上发现了这个帖子,它解释了问题发生的原因是我安装了 PyCharm 平板包。
我最终发现我的问题是由我安装 pycharm 的方式引起的。我使用了安装扁平包的应用程序商店。由于 Flatpack 的工作原理,它会安装一个包含应用程序所需的所有内容的隔离环境。对于普通应用程序来说,这可能很有用,但代价是使用额外的磁盘空间重复文件,但对于开发应用程序来说,它使得您无法从扁平化安装的应用程序内部可靠地运行代码。
-- Mvanorder1390(创建于2019年10月30日13:13)
这正是我的问题。我从官方来源重新安装了 PyCharm,而不是我的应用程序商店,它只提供了扁平化版本,现在一切都像魅力一样工作(双关语)!
| 归档时间: |
|
| 查看次数: |
1191 次 |
| 最近记录: |