获取 Python 错误“ from: can’t read/var/mail/Bio”

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

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

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

有什么问题吗?我怀疑这会有帮助,因为剧本似乎不是问题所在,但不管怎样,这是我的剧本:

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()

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

167179 次浏览

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 from keyword. (Incidentally, from is 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).

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 python instead of trying to interpret it on its own.

I ran into a similar error when trying to run a command. After reading the answer by Tamás, I realized I was not trying this command in Python but in the shell (this can happen to those new to Linux).

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

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.

./manage.py shell

and only then

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

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

#!/usr/bin/env python

or for 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 shell code. If you need to specify a manual location of the Python environment, put

#!/#path/#to/#python

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

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 python and when you get these >>> then run any python commands

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

For Flask users, before writing the commands, first make sure you enter the Flask shell using:

flask shell