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

Python

Python Problem Overview


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

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.

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 Solutions


Solution 1 - Python

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.

Solution 2 - Python

I ran into a similar error

"from: can't read /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/

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)

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

Solution 3 - Python

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

Solution 4 - Python

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 straight to the CLI. If you need to specify a manual location of python environment put

#!/#path/#to/#python

Solution 5 - Python

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

Solution 6 - 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbrucezepplinView Question on Stackoverflow
Solution 1 - PythonTamásView Answer on Stackoverflow
Solution 2 - PythonEhsan QuranwalaView Answer on Stackoverflow
Solution 3 - PythonSergii ShcherbakView Answer on Stackoverflow
Solution 4 - PythonZ.DaveyView Answer on Stackoverflow
Solution 5 - PythonDhara PatelView Answer on Stackoverflow
Solution 6 - PythonSuraj KumarView Answer on Stackoverflow