【材料学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重新打开,运行单元代码:

相关推荐
Learn-Python8 小时前
MongoDB-only方法
python·sql
小途软件9 小时前
用于机器人电池电量预测的Sarsa强化学习混合集成方法
java·人工智能·pytorch·python·深度学习·语言模型
扫地的小何尚9 小时前
NVIDIA RTX PC开源AI工具升级:加速LLM和扩散模型的性能革命
人工智能·python·算法·开源·nvidia·1024程序员节
2501_9418814010 小时前
高并发消息队列设计与优化策略在多语言系统中的实践分享
jupyter
wanglei20070810 小时前
生产者消费者
开发语言·python
清水白石00810 小时前
《从零到进阶:Pydantic v1 与 v2 的核心差异与零成本校验实现原理》
数据库·python
昵称已被吞噬~‘(*@﹏@*)’~10 小时前
【RL+空战】学习记录03:基于JSBSim构造简易空空导弹模型,并结合python接口调用测试
开发语言·人工智能·python·学习·深度强化学习·jsbsim·空战
2501_9418779811 小时前
从配置热更新到运行时自适应的互联网工程语法演进与多语言实践随笔分享
开发语言·前端·python
酩酊仙人11 小时前
fastmcp构建mcp server和client
python·ai·mcp
且去填词11 小时前
DeepSeek API 深度解析:从流式输出、Function Calling 到构建拥有“手脚”的 AI 应用
人工智能·python·语言模型·llm·agent·deepseek