获取 Python 错误“来自:无法读取 /var/mail/Bio”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16069816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 21:42:13  来源:igfitidea点击:

Getting Python error "from: can't read /var/mail/Bio"

python

提问by brucezepplin

I am running a (bio)python script which results in the following error:

我正在运行一个 (bio)python 脚本,它导致以下错误:

from: can't read /var/mail/Bio

seeing as my script doesn't have anything to with mail, I don't understand why my script is looking in /var/mail.

看到我的脚本与邮件没有任何关系,我不明白为什么我的脚本在 /var/mail 中查找。

What seems to be the problem here? i doubt it will help as the script doesn't seem to be the problem, but here's my script anyway:

这里似乎有什么问题?我怀疑它会有所帮助,因为脚本似乎不是问题,但无论如何这是我的脚本:

from Bio import SeqIO
from Bio.SeqUtils import ProtParam

handle = open("examplefasta.fasta") 
for record in SeqIO.parse(handle, "fasta"): 
    seq = str(record.seq)
    X = ProtParam.ProteinAnalysis(seq)
    print X.count_amino_acids() 
    print X.get_amino_acids_percent() 
    print X.molecular_weight() 
    print X.aromaticity() 
    print X.instability_index() 
    print X.flexibility() 
    print X.isoelectric_point() 
    print X.secondary_structure_fraction()

what is the problem here? bad python setup? I really don't think it's the script.

这里有什么问题?糟糕的python设置?我真的不认为这是剧本。

采纳答案by Tamás

No, it's not the script, it's the fact that your script is not executed by Python at all. If your script is stored in a file named script.py, you have to execute it as python script.py, otherwise the default shell will execute it and it will bail out at the fromkeyword. (Incidentally, fromis the name of a command line utility which prints names of those who have sent mail to the given username, so that's why it tries to access the mailboxes).

不,这不是脚本,而是您的脚本根本不是由 Python 执行的。如果您的脚本存储在名为 的文件中script.py,则必须将其作为 执行python script.py,否则默认 shell 将执行它并在from关键字处退出。(顺便说一下,from是一个命令行实用程序的名称,它打印向给定用户名发送邮件的人的姓名,这就是它尝试访问邮箱的原因)。

Another possibility is to add the following line to the top of the script:

另一种可能性是将以下行添加到脚本的顶部:

#!/usr/bin/env python

This will instruct your shell to execute the script via pythoninstead of trying to interpret it on its own.

这将指示您的 shell 通过执行脚本python而不是尝试自行解释它。

回答by Ehsan Quranwala

I ran into a similar error

我遇到了类似的错误

"from: can't read /var/mail/django.test.utils"

“来自:无法读取/var/mail/django.test.utils”

when trying to run a command

尝试运行命令时

>>> from django.test.utils import setup_test_environment
>>> setup_test_environment()

in the tutorial at https://docs.djangoproject.com/en/1.8/intro/tutorial05/

https://docs.djangoproject.com/en/1.8/intro/tutorial05/的教程中

after reading the answer by Tamás I realized I was not trying this command in the python shell but in the termnial (this can happen to those new to linux)

在阅读了 Tamás 的答案后,我意识到我不是在 python shell 中尝试这个命令,而是在 termnial(这可能发生在那些刚接触 linux 的人身上)

solution was to first enter in the python shell with the command python and when you get these >>> then run any python commands

解决方案是首先使用命令 python 进入 python shell,当你得到这些时 >>> 然后运行任何 python 命令

回答by Sergii Shcherbak

Same here. I had this error when running an import command from terminal without activating python3 shell through manage.py in a django project (yes, I am a newbie yet). As one must expect, activating shell allowed the command to be interpreted correctly.

同样在这里。我在从终端运行导入命令时遇到了这个错误,而没有通过 django 项目中的 manage.py 激活 python3 shell(是的,我还是个新手)。正如人们所期望的那样,激活 shell 允许正确解释命令。

./manage.py shell

and only then

然后才

>>> from django.contrib.sites.models import Site

回答by Z.Davey

Put this at the top of your .py file (for python 2.x)

把它放在 .py 文件的顶部(对于 python 2.x)

#!/usr/bin/env python 

or for python 3.x

或者对于 python 3.x

#!/usr/bin/env python3

This should look up the python environment, without it, it will execute the code as if it were not python code, but straight to the CLI. If you need to specify a manual location of python environment put

这应该查找 python 环境,没有它,它将执行代码,就好像它不是 python 代码一样,而是直接到 CLI。如果需要手动指定python环境放置的位置

#!/#path/#to/#python

回答by Suraj Kumar

for Mac OS just go to applications and just run these Scripts Install Certificates.command and Update Shell Profile.command, now it will work.

对于 Mac OS,只需转到应用程序并运行这些脚本安装 Certificates.command 和更新 Shell Profile.command,现在它就可以工作了。

回答by Dhara Patel

I got same error because I was trying to run on

我遇到了同样的错误,因为我试图继续

XXX-Macmini:Python-Project XXX.XXX$ from classDemo import MyClass

from: can't read /var/mail/classDemo

To solve this, type command pythonand when you get these >>> then run any python commands

要解决这个问题,输入命令python,当你得到这些时 >>> 然后运行任何 python 命令

>>>from classDemo import MyClass
>>>f = MyClass()