简体   繁体   中英

Fatal Python error: initfsencoding: Unable to get the locale encoding File “/cm/shared/apps/anaconda2/4.5.12/lib/python2.7/encodings/__init__.py”

I am writing a job submission script for SLURM workload manager. First, I have loaded anaconda2/4.5.12 (including python 2.7) module. Then, I have created conda environment with Python3.7 version. I try to submit the script using "sbatsh" command, but I get this error:

Fatal Python error: initfsencoding: Unable to get the locale encoding
File "/cm/shared/apps/anaconda2/4.5.12/lib/python2.7/encodings/__init__.py", line 123
raise CodecRegistryError,\
                        ^
SyntaxError: invalid syntax
Current thread 0x00002aaaaaaffc00 (most recent call first):
/cm/local/apps/slurm/var/spool/job04287/slurm_script: line 19: 40032 
Aborted                 python3 taxo.TXT

This is my script file:

#!/bin/bash
#
#SBATCH --job-name=taxjob
#SBATCH --nodes=4

#SBATCH --tasks-per-node=3
#SBATCH --time=0-03:00:00
#SBATCH --partition=shortq 
#SBATCH --mem=24GB 
#SBATCH --output=/home/s.e/tax/Ftest-%j.out
#SBATCH --error=/home/s.e/tax/Ftest-%j.err
module load anaconda2/4.5.12
source activate py37
python3  taxo.TXT

The problem is that the "/cm/shared/apps/anaconda2/4.5.12/lib/python2.7/encodings/__init__.py" if a python2 file, like you can see at the path, but it is trying to be interpreted as a python3 file. You can either fix this conda problem and run it using python2.7 or edit the encodings/__init__.py file to make it python3-interpretable

To understand the problem you can try to run this line in python2 and python3 manually:

#Python3
>>> raise Exception,\
  File "<stdin>", line 1
    raise Exception,\
                   ^
SyntaxError: invalid syntax

but

#Python2.7
>>> raise Exception,\
...

Python3 analog of raise Exception,\\ "str" is raise Exception("str") . So you can change the 123rd line of the file, but it's not a good idea, because other problems may occur, so it's better to fix something in configs/executing commands of anaconda

After many tries, the solution was to add the instruction "unset PYTHONPATH" to my script file as follows:

....    
module load anaconda2/4.5.12
source activate py37
unset PYTHONPATH
python3  taxo.TXT

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM