cndaqiang Web Linux DFT

[linux]Anaconda安装

2019-05-03
cndaqiang
RSS

常用命令

激活环境
conda activate python37 # for Linux & Mac
#老版 source activate python37 # for Linux & Mac
退出环境
conda deactivate python37 # for Linux & Mac
#老版 source deactivate python37 # for Linux & Mac

下载

下载后,直接运行

wget https://repo.anaconda.com/archive/Anaconda2-2019.03-Linux-x86_64.sh
./Anaconda2-2019.03-Linux-x86_64.sh

安装后,添加PATH

export PATH=/home/cndaqiang/anaconda2/bin:$PATH

自定义模块

export PYTHONPATH="${PYTHONPATH}:${HOME}/MyTools/TDAP/py/module"

查看已有环境

~ $ conda info --env
# conda environments:
#
base                  *  /Users/cndaqiang/anaconda3
python27                 /Users/cndaqiang/anaconda3/envs/python27

创建环境

创建环境
conda create --name python37 python=3.7
激活环境
conda activate python37 # for Linux & Mac
退出环境
conda deactivate python37 # for Linux & Mac
删除环境
conda remove --name python37 --all
#通常默认创建的base环境包含很多库了,可以复制减少安装过程
conda create -n python37  --clone base

配置环境

指定环境按照程序包
conda install -n python37 numpy
更新
conda update -n python37 numpy
删除
conda remove -n python37 numpy

也可以进入环境后

python -m pip install 

查看安装的包

conda list [ -n python37]

删除没用的包

conda clean -p      //删除没有被依赖的包,一下就删除了3GB.
conda clean -t      //删除tar包
conda clean -y --all //删除所有的安装包及cache

其他软件包

conda install -n python37 numpy
conda install -n python37 matplotlib
conda install -n python37 pandas
conda install -n python37 scipy
#自动输入脚本
echo y  | conda install -n  python37 numpy
echo y  | conda install -n  python37 matplotlib
echo y  | conda install -n  python37 pandas
echo y  | conda install -n  python37 scipy

pymatgen

自动调整matplot画图的text位置

conda install -c conda-forge adjusttext

pip离线安装包

下载https://pypi.org/,安装

python -m pip install adjustText-0.7.3.tar.gz

更换仓库加速安装

清华-Anaconda 镜像使用帮助
vi ~/.condarc 填入

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

使用mamba加速安装

安装mamba可以使用conda镜像,使用mamba安装其他包时,在~/.condarc设置镜像可能导致安装失败

安装 mamba

conda install mamba -n dft37 -c conda-forge

使用mamba安装包示例:triqs

mamba install  -c conda-forge triqs

大多数conda的命令,可以直接替换conda为mamba

mamba create --name python37 python=3.7
mamba install  numpy matplotlib pandas scipy -n python37
mamba activate python37
#完全可以
alias conda=mamba

有趣的库

图片exif查看修改

python -m pip install pyexiv2

使用

>>> from pyexiv2 import Image
>>> i=Image("IMG_20210502_134203.jpg")
>>> i.read_exif()
{'Exif.Image.ImageWidth': '4000', 'Exif.Image.Model': 'MI 9', 'Exif.Image.ImageLength': '3000', 'Exif.Image.Orientation': '1', 'Exif.Image.DateTime': '2021:05:02 13:42:05', 'Exif.Image.YCbCrPositioning': '1', 'Exif.Image.ExifTag': '206', 'Exif.Photo.0x9aaa': '56 215 229 108 207 190 100 102 189 201 147 196 56 34 235 201 1
.....
#修改exif
>>> i.modify_exif({'Exif.Image.Make': 'cndaqiang'})
#关闭,保存修改
>>> i.close()

修改后就不同了

>>> import filecmp
>>> filecmp.cmp("IMG_20210502_134203.jpg","IMG_20210502_134203的副本.jpg")

对另一个文件做同样的更改,就相同了

>>> i=Image("IMG_20210502_134203的副本.jpg")
>>> i.modify_exif({'Exif.Image.Make': 'cndaqiang'})
>>> i.close()
>>> filecmp.cmp("IMG_20210502_134203.jpg","IMG_20210502_134203的副本.jpg")
True

Jupyter

Ubuntu安装Jupyter notebook——开启远程访问

安装

conda install jupyter 
conda install notebook

启动

(python37) cndaqiang@mac ~$ jupyter notebook
[I 21:19:48.581 NotebookApp] 把notebook 服务cookie密码写入 /Users/cndaqiang/Library/Jupyter/runtime/notebook_cookie_secret
[I 21:19:49.069 NotebookApp] 启动notebooks 在本地路径: /Users/cndaqiang
[I 21:19:49.069 NotebookApp] Jupyter Notebook 6.4.3 is running at:
[I 21:19:49.069 NotebookApp] http://localhost:8888/?token=70eee734a61b7c748ccd3c9c712ba5228deb0c5076b919fc
[I 21:19:49.069 NotebookApp]  or http://127.0.0.1:8888/?token=70eee734a61b7c748ccd3c9c712ba5228deb0c5076b919fc
[I 21:19:49.069 NotebookApp] 使用control-c停止此服务器并关闭所有内核(两次跳过确认).
[C 21:19:49.237 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///Users/cndaqiang/Library/Jupyter/runtime/nbserver-8614-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=70eee734a61b7c748ccd3c9c712ba5228deb0c5076b919fc
     or http://127.0.0.1:8888/?token=70eee734a61b7c748ccd3c9c712ba5228deb0c5076b919fc
/Users/cndaqiang/anaconda3/envs/python37/lib/python3.7/json/encoder.py:257: UserWarning: date_default is deprecated since jupyter_client 7.0.0. Use jupyter_client.jsonutil.json_default.
  return _iterencode(o, 0)

配置

配置文件: ~/.jupyter/jupyter_notebook_config.json

命令启动

  • 使用密码登录:浏览器无痕模式打开http://127.0.0.1:8888输入token和新密码就可以用密码登录了,密码自动写入配置文件
  • 恢复token:删除 ~/.jupyter/jupyter_notebook_config.json
  • 指定ip端口,并不要自动打开浏览器jupyter notebook --port 1234 --ip 192.168.192.167 --no-browser

使用配置文件控制

  • 生成配置文件jupyter notebook --generate-config
  • 生成迷文密码:
    (python37) cndaqiang@mommint:~$ python
    Python 3.7.9 (default, Aug 31 2020, 12:42:55)
    [GCC 7.3.0] :: Anaconda, Inc. on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from notebook.auth import passwd
    >>> passwd()
    Enter password:
    Verify password:
    'argon2:$argon2id$v=19$m=10240,t=10,p=8$xu/mq1dTF9vs9v6JKiBMUQ$6phhCcBl/Ri6UgHlI681Uw'
    
  • 修改配置文件
    (python37) cndaqiang@mommint:~$ grep -v '^#' ~/.jupyter/jupyter_notebook_config.py | grep -v '^$'
    c.NotebookApp.allow_remote_access = True  #打开远程访问
    c.NotebookApp.ip = '192.168.192.204'  #指定ip
    c.NotebookApp.open_browser = False  #不开浏览器
    c.NotebookApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$xu/mq1dTF9vs9v6JKiBMUQ$6phhCcBl/Ri6UgHlI681Uw' #密码同上
    c.NotebookApp.port = 1234 #端口
    
  • 启动jupyter notebook

添加到系统服务

问题

Traceback (most recent call last):
  File "/home/cndaqiang/anaconda3/bin/conda", line 7, in <module>
    from conda.cli import main
ModuleNotFoundError: No module named 'conda'

重新安装修复

./Anaconda3-5.3.1-Linux-x86_64.sh -u

anaconda安装的mpi和系统的mpi冲突,卸载anaconda安装的mpi

#查询包名称
conda list
#卸载
conda uninstall mpi

安装ase,及其他

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple  ase
#
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple uncertainties
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple lmfit

NFS服务器连接断开, anaconda命令会卡死

这样加一道检测命令

networkOK=$(ping -t 1 -c 1 mom | grep round-trip | tail | awk '{ print $NF }')
if [ $networkOK  ] 
then
  conda activate python37 #& #pid=$! ;sleep 5; kill -9 $pid
else
  echo "Can't mount mom, stop conda, Please not run: conda activate python37"
fi

CondaHTTPError:

(python37) cndaqiang@mac zim-0.74.2$ conda install mamba -c conda-forge
Solving environment: failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/osx-64/repodata.json>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
SSLError(MaxRetryError('HTTPSConnectionPool(host=\'mirrors.tuna.tsinghua.edu.cn\', port=443): Max retries exceeded with url: /anaconda/pkgs/r/osx-64/repodata.json (Caused by SSLError(SSLError("bad handshake: Error([(\'SSL routines\', \'ssl3_get_server_certificate\', \'certificate verify failed\')])")))'))


(python37) cndaqiang@mac zim-0.74.2$ conda config --set ssl_verify no #没用

无解

卡在Solving environment: done

无解,重新创建新的环境就可以

FileNotFoundError

ERROR conda.core.link:_execute(502): An error occurred while installing package 'conda-forge::certifi-2022.9.24-pyhd8ed1ab_0'.
FileNotFoundError(2, "No such file or directory: '/public/home/cndaqiang/anaconda3/envs/xTB/bin/python3.9'")
Attempting to roll back.

Rolling back transaction: done

FileNotFoundError(2, "No such file or directory: '/public/home/cndaqiang/anaconda3/envs/xTB/bin/python3.9'")

更新

conda update -n base -c defaults conda

本文首发于我的博客@cndaqiang.
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!



评论


广告

目录

广告
访客数据