Ubuntu24.04安装Anaconda3+Pycharm
一、引言
重装系统已经过去一段时间了,现在安装一下 Anaconda 和 Pycharm。
参考连接:
- Ubuntu中安装Anaconda3和Pycharm 及其环境搭建
- Ubuntu18.04安装Pycharm教程
- ubuntu系统安装Anaconda及Pycharm
- 在移动硬盘上搭建Ubuntu24.04深度学习环境(Anaconda + CUDA + Pytorch)
二、安装 Anaconda
1. Ubuntu 更换下载源
设置 root 账户:
sudo passwd root
进入 root 账户:
su root
使用gedit文本编辑器打开sources文件:
sudo gedit /etc/apt/sources.list.d/ubuntu.sources
将内容替换为:
Types: deb deb-src
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-backports noble-security noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb deb-src
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
Suites: noble noble-updates noble-backports noble-security noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb deb-src
URIs: http://mirrors.163.com/ubuntu/
Suites: noble noble-updates noble-backports noble-security noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb deb-src
URIs: https://mirrors.ustc.edu.cn/ubuntu/
Suites: noble noble-updates noble-backports noble-security noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://cn.archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
更新下载源:
sudo apt-get update
2. 安装 Anaconda
首先在镜像站下载Anaconda:清华大学开源软件镜像站
我下载的版本是:Anaconda3-2024.06-1-Linux-x86_64.sh
打开 sh 文件所在文件夹,右键用终端打开,安装:
bash Anaconda3-2024.06-1-Linux-x86_64.sh -b -p /xxx/xxx/anaconda3
然后会出现满屏的协议,一直回车或者下箭头,输入 yes 同意协议并继续安装,选择安装路径:
安裝之后默认没配置环境变量,选 no:
installation finished.
Do you wish to update your shell profile to automatically initialize conda?
This will activate conda on startup and change the command prompt when activated.
If you'd prefer that conda's base environment not be activated on startup,
run the following command when conda is activated:
conda config --set auto_activate_base false
You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> no
You have chosen to not have conda modify your shell scripts at all.
To activate conda's base environment in your current shell session:
eval "$(/.../.../anaconda3/bin/conda shell.YOUR_SHELL_NAME hook)"
To install conda's shell functions for easier access, first activate, then:
conda init
Thank you for installing Anaconda3!
3. 添加环境变量
sudo gedit ~/.bashrc # 打开.bashrc文件
export PATH=~/anaconda3/bin:$PATH # 在上一条命令打开的的.bashrc文件中最后一行新增环境变量,前提是安装anaconda3时安装在home/username/下,保存。或者直接写入绝对路径,则不需要在最开始添加~
source ~/.bashrc # 使其生效
conda -V
注意这里是大写的 V。
4. 换源
先生成.condarc文件:
conda config
打开文件:
sudo gedit ~/.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/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
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
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
验证是否更改成功:
conda config --show-sources
三、安装 Pycharm
1.下载Pycharm
官网链接:下载 PyCharm:JetBrains 出品的用于数据科学和 Web 开发的 Python IDE
选择其他版本,下载社区版。解压到本地后,打开文件夹,cd 到 bin 文件夹下,用终端打开,执行:
2. 安装
bash pycharm.sh
安装成功。
3. 生成快捷图标
这里我安装了两次 pycharm,一次是联网安装的,安装过后没什么问题。第二次是离线安装的,安装过后出现了几个警告,并且没有快捷图标。想要生成快捷图标的话,在Tools里选择“Creat DeskTop Entry…“ 即可。
4. 汉化 pycharm
- Files–>Settings
这里我已经安装好了中文插件。 - 设置中文
重启 Pycharm。
四、卸载Anaconda
参考链接:Ubuntu卸载Anaconda步骤
1. 进行相关文件的删除(删除12个文件夹)
- 删除anaconda3文件夹
rm -rf ~/anaconda3
- 删除.anaconda文件夹
rm -rf ~/.anaconda
- 删除.condarc文件夹
rm -rf ~/.condarc
- 删除.conda文件夹
rm -rf ~/.conda
- 删除.continuum文件夹
rm -rf ~/.continuum
- 删除.ipython文件夹
rm -rf ~/.ipython
- 删除/.local/share/jupyter
rm -rf ~/.local/share/jupyter
- 删除/.local/share/Spyder
rm -rf ~/.local/share/Spyder
- 删除/.config/spyder-py3
rm -rf ~/.config/spyder-py3
- 删除/.jupyter文件夹
rm -rf ~/.jupyter
- 删除/.ipynb_checkpoints文件夹
rm -rf ~/.ipynb_checkpoints
- 删除/.keras文件夹
rm -rf ~/.keras
2. 删除 anaconda配置的环境变量
删除Anaconda·配置的环境变量
- 打开/.bashrc文件
sudo gedit ~/.bashrc
- 编辑/.bashrc内容
(1) 删除 包含 # >>> conda initialize >>>与# <<< conda initialize <<<以及两者之间的所有内容
,例如:
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/alice/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/alice/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/alice/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/alice/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
(2) 如果末尾有自己添加的anaconda路径内容,也要删除
将末尾的此行删除
# added by Anaconda3 installer
export PATH="/home/alice/anaconda3/bin:$PATH"
此处的alice应为你的实际用户名
- 更新环境变量,使更改生效
命令如下:
source ~/.bashrc
至此,anaconda 已经完全被卸载,可进行Anaconda 的重新安装。
五、卸载pycharm
参考链接:如何在Ubuntu系统中卸载PyCharm
1. 删除PyCharm安装目录
sudo rm -rf /opt/pycharmX.x.x
2. 清理残留PyCharm文件
- 在 home 目录下使用 find 命令来搜索与 PyCharm 相关的所有配置文件和目录:
sudo find . -name "*PyCharm*"
确认这些文件确实与PyCharm有关后,逐一删除:
rm -rf .PyCharmX.x.x
- 在系统级使用 find 命令来搜索与 PyCharm 相关的所有配置文件和目录:
sudo find /etc -name "*PyCharm*"
- 在系统日志中使用 find 命令来搜索与 PyCharm 相关的所有配置文件和目录:
sudo find /var/log -name "*PyCharm*"
我最终删除的文件有:
rm -rf ~/.PyCharm*
rm -rf ~/.config/JetBrains/PyCharm*
rm -rf ~/.cache/JetBrains/PyCharm*
rm -rf ~/.pycharm_helpers/
rm -rf ~/.java/.userPrefs/jetbrains/pycharm
3. 更新系统
sudo apt update
作者:一个没有本领的人