【材料学python入门】conda、 jupyter、cpu、GPAW、wsl、ubuntu

Win10(无gpu)

安装Anaconda3

历史版本: https://repo.anaconda.com/archive/

查找:Anaconda3-2024.10-1-Windows-x86_64.exe



配置环境变量

bash 复制代码
D:\Environment\anaconda3
D:\Environment\anaconda3\Scripts
D:\Environment\anaconda3\Library\bin

创建环conda环境

bash 复制代码
conda create --name abtem12 python=3.12
conda activate abtem12
conda env list

pycharm连接conda环境


安装 jupyter、notebook

bash 复制代码
conda activate abtem12
conda install jupyterlab  
conda install -c conda-forge notebook
bash 复制代码
python -m ipykernel install --user --name abtem --display-name "Python (abtem)"
jupyter kernelspec list

右上角切换到abtem

安装pytorch

复制代码
conda activate abtem12
conda install pytorch torchvision torchaudio cpuonly -c pytorch
python 复制代码
from torch import __version__ 
print( __version__)                    

Ubuntu22.04 (wsl备用)

直接微软应用商店下载 Ubuntu22.04

安装Anaconda3

bash 复制代码
# 下载
cd ~
pwd
wget https://repo.anaconda.com/archive/Anaconda3-2025.06-0-Linux-x86_64.sh
bash 复制代码
# 安装
sh Anaconda3-2025.06-0-Linux-x86_64.sh
# 输入q,跳过协议阅读
# yes
# 回车
# 等。。。
# 回车

配置环境:

复制代码
ubuntu22@Autumn:~$ echo 'export PATH="$HOME/anaconda3/bin:$PATH"' >> ~/.bashrc
ubuntu22@Autumn:~$ source ~/.bashrc
ubuntu22@Autumn:~$ conda --version

创建conda环境

bash 复制代码
conda create -n abtem39wsl python=3.9
conda activate abtem39wsl

如果报错: CondaError: Run 'conda init' before 'conda activate'

bash 复制代码
# 初始化 conda
$HOME/anaconda3/bin/conda init bash

新开终端,看到有bash了,再次执行:conda activate abtem39wsl

pycharm连接wsl



右下角👇

bash 复制代码
 conda install jupyterlab
 
 python -m ipykernel install --user --name abtem39wsl--display-name "Python (abtem39wsl)"
 jupyter kernelspec list

 conda install -c conda-forge notebook

更换内核👇

GPAW

conda下载
bash 复制代码
# 查找
conda search gpaw -c conda-forge
# 选22.1.0 py39是当前conda环境的py是3.9版本的
conda install gpaw=22.1.0=py39_mpi_mpich_omp_1 -c conda-forge
测试
  1. 导包测试:
  2. 数据集测试:
bash 复制代码
pip install pytest
which gpaw
cd /home/ubuntu22/anaconda3/envs/abtem39wsl/bin/
bash 复制代码
pytest --pyargs gpaw -n 16
pytest --version
pip install pytest-xdist
pytest --pyargs gpaw -n 16


结束。

RuntimeError: Could not find required PAW dataset file "C.LDA".

因为路径里都是 C.LDA.gz 这样的压缩包,需要解压:

bash 复制代码
$ echo $GPAW_SETUP_PATH
# /home/ubuntu22/anaconda3/envs/abtem39wsl/share/gpaw

$ cd /home/ubuntu22/anaconda3/envs/abtem39wsl/share/gpaw

$ for f in *.gz; do gunzip -c "$f" > "${f%.gz}"; done

$ ls -l C.LDA
# -rw-r--r-- 1 ubuntu22 ubuntu22 125417 Oct  8 09:26 C.LDA

$ which python
# /home/ubuntu22/anaconda3/envs/abtem39wsl/bin/python

$ python -c "import gpaw; print(gpaw.setup_paths)"
# ['/home/ubuntu22/anaconda3/envs/abtem39wsl/share/gpaw']

让服务器重启,关闭pycharm重新打开,运行单元代码:

相关推荐
金銀銅鐵19 小时前
[Python] 基于欧几里得算法,实现分数约分计算器
python·数学
Lyn_Li20 小时前
Kaggle Top 5 | 198只股票、200条数据的金融预测——BattleFin高分方案从零复现
python·kaggle·比赛复盘·金融预测
小九九的爸爸1 天前
前端想要入门Agent开发,要具备哪些Python基础?
python·agent·ai编程
阿耶同学1 天前
手把手教你用 LangGraph 搭建三层嵌套 Agent 架构
python·程序员
花酒锄作田2 天前
Pydantic校验配置文件
python
hboot2 天前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi2 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi2 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽2 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户8358086187912 天前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python