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

相关推荐
2601_962885729 小时前
2026 Python 股票数据接口选型指南(横评 + 决策树)
开发语言·python·区块链
龙腾AI白云10 小时前
大模型检索增强生成(RAG)的技术原理与架构设计
数据库·python·机器学习·知识图谱
fanruitian10 小时前
python 可视化 panda seaborn matplotlib.pyplot
开发语言·python·matplotlib
梦想不只是梦与想10 小时前
Python 中的 json 模块
python·json·对象转字符串
星河耀银海10 小时前
Python文件操作:read、readline、readlines读取方式对比
python·文件操作·面向对象·基础函数·教程学习
傅科摆 _ py11 小时前
DP,贪心,堆和栈,二分力扣复习
开发语言·python·算法
吴名氏.11 小时前
Java转AI Agent教程(第一周)让模型先跑起来
人工智能·python·ai·ai agent
第404号工位12 小时前
离职退电脑前别只点“清空回收站”!手把手教你彻底抹除凭证与数字痕迹
linux·python·架构
Metaphor69212 小时前
使用 Python 在 Word 文档中添加、修改和删除变量
python·word
終不似少年遊*12 小时前
【AI Coding实战方法论】从计划协作到架构护栏,一套能长期复用的工程流程
人工智能·python·团队开发·ai编程·ai coding·skills·上下文管理