VirtualBox7.0|ubuntu22.04|conda23|jupyter notebook集成环境安装配置及国内源更换-保姆级配置教程

安装环境

VirtualBox7.0+ubuntu-22.04+conda 23(含jupyter notebook安装调试)集成环境

记录目的

智能 AI 代理项目SFighterAI项目配置过程中用到的安装环境配置相关步骤及问题结局。

VirtualBox7.0安装及配置

安装流程可参考:
VirtualBox安装Ubuntu20.04图文教程
最全ubuntu-Anaconda换源问题/恢复默认源,一篇就够

VBox增强功能安装及共享文件夹配置

VBox增强功能安装

虚拟机顶端选择设备-分配光驱,加载虚拟盘:VBoxLinuxAdditions.iso,执行安装增强功能进行安装。
在这里插入图片描述 当加载光盘不能正常安装增强功能(VBoxLinuxAdditions),可进入光盘文件目录,ctrl+shift+T打开teminal,执行:

sudo sh VBoxLinuxAdditions.run

安装中:
在这里插入图片描述
若采用最小安装,则依赖会存在问题,提示需要安装: gcc make perl,

安装方法:

ctrl+alt++T,打开终端,执行以下代码:

sudo apt-get install gcc make perl -y
reboot
#systemctl reboot  //reboot无效时执行
#systemctl default or  exit 

正常安装后,启用共享剪贴板(双向),拖放(双向),便于虚拟机与主机的共享操作。
在这里插入图片描述
完成后root。

共享文件夹建立

先主机(本机为windows11)建立共享文件夹,并开启共享权限。
虚拟机端建立共享文件夹:
在这里插入图片描述
选择主机端建立的共享文件夹名称,自动挂载+固定分配,并进行相关设置:
在这里插入图片描述至此,应该已经能够看到共享文件夹中的内容:
在这里插入图片描述

补充资料:

Ubuntu系统下安装Anaconda + Jupyter Notebook + Python + R

更换系统源

终端中运行:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #备份
sudo gedit /etc/apt/sources.list #修改

# 阿里云源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse


# 清华大学源
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

源更新:
$sudo apt-get update
ubuntu系统与软件更新。
$sudo apt-get upgrade

anaconda安装

下载安装包:64-Bit (x86) Installer (860 MB)
在主目录下新建一个名为anaconda的文件夹,并将刚刚下载的文件放在此文件夹中,如:
/home/testlinux/anaconda
右键点击文件夹,点击在终端中打开
执行
bash Anaconda3-2023.03-Linux-x86_64.sh
enter至出现要求输入选项,输入yes,****,yes
输入enter,确认安装目录,开始安装,
Do you wish the installer to initialize Anaconda3
by running conda init?
输入yes
等待安装完成。

将bin路径加入系统path变量

echo ‘export PATH=“/home/testlinux/anaconda3/bin:$PATH”’ >> ~/.bashrc
source ~/.bashrc
此时在anaconda的安装目录anaconda3文件夹中,终端中输入conda list,可以看到anaconda的安装的包。

增加源

conda config --show channels #查看目前已有的镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ #添加清华源
conda config --set show_channel_urls yes#从channel中安装包时显示channel的url,这样就可以知道包的安装来源
可参考:
最全ubuntu-Anaconda换源问题/恢复默认源,一篇就够
ubuntu 更换系统软件源 和 pip源
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/

如果要删除:

conda config --remove channels https://pypi.tuna.tsinghua.edu.cn/simple/
打开anconda prompt 输入conda clean -i `
清除索引缓存,保证用的是镜像站提供的索引。
可以尝试去更改.condarc文件。如果是root用户登入Linux那么这个文件就在“/root/”,如果是其他用户则在“/home/username/”(有可能被隐藏,按Ctrl+h会显示);windows则在“C:\Users\用户名”。
更改为(去掉-和defaults):

vi  ~/.condarc

channels:
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
  - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true

更新conda及安装Python环境

conda update --name base conda

验证及查看配置

conda config --show channels #验证一下配置是否成功

配置及激活环境

conda create -n StreetFighterAI python=3.8.10

激活命令

Windows:conda init <SHELL_NAME>
SHELL_NAME 替换成当前的shell名称,比如 Windows 一般是 conda init cmd
Linux:一般是 source activate
conda activate StreetFighterAI

更新pip源

原文链接:ubuntu更换pip源
临时使用
pip3 install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install jupyter_contrib_nbextensions -i https://pypi.tuna.tsinghua.edu.cn/simple
更换pip源
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:https://mirrors.aliyun.com/pypi/simple
进入配置(如果没有,先新建一个)
$ sudo mkdir ~/pip
$ sudo gedit ~/pip/pip.conf
修改内容如下:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple
[install]
trusted-host=mirrors.aliyun.com

无法写入pip.conf错误解决

可用下面的命名查看buftype的设置,当buftype=nofile时,不能保存文件,只有当buftype=空时,才可以保存

:verbose set buftype
1
修改buftype的方法:vim切换至ex模式,输入

:setlocal buftype=
1
如果想该回原设置,可用下面的命令:

:setlocal buftype=nofile
1

Jupyter Notebook安装配置

安装jupyter notebook

依次执行四条命令,第三条命令为设置密码
conda install jupyter notebook -y
jupyter notebook --generate-config
jupyter notebook password
password:自己设定

[NotebookPasswordApp] Wrote hashed password to /home/testlinux/.jupyter/jupyter_notebook_config.json

免密码登录

编辑jupyter_notebook_config.py:

cd ~/.jupyter/
gedit jupyter_notebook_config.py

将c.NotebookApp.token赋为空值,即:
c.NotebookApp.token = ‘’

安装ipykernel

conda install ipykernel -y
python -m ipykernel install --user --name StreetFighterAI --display-name StreetFighterAI

运行 Jupyter Notebook

运行:
$ jupyter notebook
浏览器打开:
http://localhost:8888/
输入密码,正常进入环境。
在这里插入图片描述
测试代码:
在这里插入图片描述

代码自动补全扩展

首先安装扩展库
pip install jupyter_contrib_nbextensions
jupyter contrib nbextensions install --user
pip install jupyter_nbextensions_configurator

安装完成后,重新启动Jupyter notebook
点开Nbextensions选项,并勾选 Hinterland

Tips:linux重启命令 :

1、reboot 
2、shutdown -r now 立刻重启
3、shutdown -r 10 过10分钟自动重启
4、shutdown -r 20:35 在时间为20:35时候重启

如果是通过shutdown命令设置重启的话,可以用shutdown -c命令取消重启 

关机命令 : 
1、halt   立刻关机(一般加-p 关闭电源)
2、poweroff 立刻关机 
3、shutdown -h now 立刻关机
4、shutdown -h 10 10分钟后自动关机 

如果是通过shutdown命令设置关机的话,可以用shutdown -c命令取消关机

猜你喜欢

转载自blog.csdn.net/Medlar_CN/article/details/130255286