normal version python
Some Differences between Python 2 and Python 3
print "aa" |
print("aa") |
raw_input("name:") |
input("name:") |
dict.keys().sort().reverse() |
sorted(dict.keys()).reverse() |
4/2=2 |
/2=2.0 |
print >>sys.staerr, "fatal error" |
print ("fatal error", file=sys.stderr) |
Tips
- pause:
os.system("pause")
;
- 每一个变量和数组都要初始化, 如
list = [0]*12 or list =[0,0,0,0,0,0,0,0,0,0,0,0]
,下标0-11
- range(1,12)为1-11,range(12)为0-11.
obj= {100: 0.01, 60: 0.015},keys = sorted(obj.keys()).reverse, for key in keys:... obj.get(key)...
d= []; d.append(a); d.append([a,b]); c=(i%1000)//100
b = a[:]
数组复制
print(i,"*",j,"=",mul,"\t",end="");
不换行,输出时最后要加上print("")
- 当前时间:
time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
- Exit cycle:
break
, nothing: pass
- logical difine:
LRun = False
import numpy as np; print(np.sqrt(3));
- 格式化输出:
print('英文 = %s,空格 = %s,数字 = %s,其他 = %s' % (char,space,num,other))
- 判断类型
i.isalpha();i.isspace();i.isnumeric()
or import re;re.match('[a-zA-Z]',i);re.match('\s',i);re.match('\d',i)
install conda python
wget https://repo.anaconda.com/miniconda/Miniconda3-py38_23.1.0-1-Linux-x86_64.sh
bash Miniconda3-py38_23.1.0-1-Linux-x86_64.sh -b -p condahome
eval "$(condahome/bin/conda shell.bash hook)"
#conda update --yes conda
conda config --add channels conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
- install phonopy on one computer
conda create -n phonopy python=3.8
conda activate phonopy
conda install seekpath scipy spglib ase
conda install -c conda-forge phonopy phono3py
cd condahome
tar -cvf phonopy.tgz pkgs/ envs/phonopy/
conda deactivate
## copy phonopy.tgz to another coputer
## uset seperate env for other package, such as pymatgen,thirdorder
conda create -n bte python=3.6
conda activate
conda install numpy scipy
conda deactivate
- install phonopy on another computer offline
bash Miniconda3-py39_23.1.0-1-Linux-x86_64.sh -b -p ~/.soft_local/miniconda
rm -rf /home/muyw/.soft/miniconda/pkgs
tar -xvf pyclone.tgz
mv pkgs /home/muyw/.soft/miniconda/
eval "$(~/.soft_local/miniconda/bin/conda shell.bash hook)"
## conda remove -n phonopy --all
conda create -n phonopy --clone envs/phonopy
conda create -n bte --clone envs/bte
conda create -n py2 python=2.7
conda activate py2
conda install nomkl numpy
conda deactivate
Commands
# conda install package_name
# conda remove package_name
# conda update package_name
# 查看已安装的包
conda list
# 搜索安装包
conda search search_term
# 安装指定版本的包
conda install numpy=1.11
# 更新环境中的所有包
conda update --all
#######################
# 安装numpy,scipy,matplotlib
conda install numpy scipy matplotlib
conda install spglib ase
Win10
- 安装Anaconda3
- Add the paths for
anaconda3
, anaconda3/Scripts
and anaconda3\Library\bin
to envirenment variable PATH
.
conda install -c conda-forge ase seekpath pymatgen
install python with pip
## Download
wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz
tar -xvf Python-3.10.9.tgz
cd Python-3.10.9
## Install
./configure --prefix=/home/muyw/.soft/python3 --enable-optimizations --enable-shared
make
make install
## Environmet Variable
export PYTHON_HOME=/home/muyw/.soft/python3
export PATH=${PYTHON_HOME}/bin:$PATH
## pip install
pip3 install numpy scipy h5py pyyaml matplotlib
pip3 install spglib ase seekpath
Errors
- Ref: 解决:pip is configured with locations that require TLS/SSL_witton的博客-CSDN博客_pip is configure with location
mkdir ~/.pip
vi ~/.pip/pip.config
### add
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com