VirtualBox7.0|ubuntu22.04|conda23|jupyter notebook integrated environment installation configuration and domestic source replacement - nanny level configuration tutorial

Installation Environment

VirtualBox7.0+ubuntu-22.04+conda 23 (including jupyter notebook installation and debugging) integrated environment

Record purpose

The relevant steps of the installation environment configuration used in the configuration process of the intelligent AI agent project SFighterAI project and the problem outcome.

VirtualBox7.0 installation and configuration

For the installation process, please refer to:
VirtualBox installation Ubuntu20.04 graphic tutorial
is the most complete ubuntu-Anaconda source replacement problem/restoring the default source, one article is enough

VBox enhanced function installation and shared folder configuration

VBox Enhancements Installation

Select the device at the top of the virtual machine - assign the optical drive, load the virtual disk: VBoxLinuxAdditions.iso, and execute the installation enhancement function to install.
insert image description hereWhen the enhanced function (VBoxLinuxAdditions) cannot be installed normally after loading the CD, you can enter the file directory of the CD, ctrl+shift+T to open teminal, and execute:

sudo sh VBoxLinuxAdditions.run

Installing:
insert image description here
If the minimum installation is used, there will be problems with dependencies, prompting the need to install: gcc make perl,

installation method:

ctrl+alt++T, open the terminal, execute the following code:

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

After normal installation, enable the shared clipboard (two-way), drag and drop (two-way), to facilitate the sharing operation between the virtual machine and the host.
insert image description here
root when done.

Create a shared folder

First, the host (this machine is windows11) creates a shared folder and opens the sharing permission.
Create a shared folder on the virtual machine side:
insert image description here
Select the name of the shared folder created on the host side, automatically mount + fixed allocation, and make related settings:
insert image description hereAt this point, you should be able to see the contents of the shared folder:
insert image description here

additional materials:

Install Anaconda + Jupyter Notebook + Python + R in Ubuntu system

Replace system source

Run in the terminal:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #Backup
sudo gedit /etc/apt/sources.list #Modify

# 阿里云源
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

Source update:
$ sudo apt-get update
ubuntu system and software update.
$ sudo apt-get upgrade

anaconda installation

Download the installation package: 64-Bit (x86) Installer (860 MB)
Create a new folder named anaconda in the main directory, and put the downloaded file in this folder, such as:
/home/testlinux/anaconda
right click Click the folder, click to open in the terminal,
execute
bash Anaconda3-2023.03-Linux-x86_64.sh
enter until the input option appears, enter yes, ****, yes
enter enter, confirm the installation directory, start the installation,
Do you wish the installer to initialize Anaconda3
by running conda init?
Enter yes
and wait for the installation to complete.

Add the bin path to the system path variable

echo 'export PATH="/home/testlinux/anaconda3/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
is now in the anaconda3 folder of the anaconda installation directory, enter conda list in the terminal, you can see to the package installed by anaconda.

increase source

conda config --show channels #View existing mirrors
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ #Add Tsinghua source
conda config --set show_channel_urls yes #Display the url of the channel when installing the package from the channel, so that you can know the installation source of the package. You can
refer to:
The most complete ubuntu-Anaconda source replacement problem/restoring the default source, one article is enough for
ubuntu to replace the system software source and pip source
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/

If you want to delete:

conda config --remove channels https://pypi.tuna.tsinghua.edu.cn/simple/
Open the anconda prompt and enter conda clean -i `
to clear the index cache and ensure that the index provided by the mirror site is used.
You can try to change the .condarc file. If the root user logs in to Linux, then this file is in "/root/", if it is another user, it is in "/home/username/" (it may be hidden, press Ctrl+h to display it); windows is in "C: \Users\Username".
Change to (remove - and 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

Update conda and install Python environment

conda update --name base conda

Verify and view configuration

conda config --show channels #Verify whether the configuration is successful

Configure and activate the environment

conda create -n StreetFighterAI python=3.8.10

activate command

Windows: conda init <SHELL_NAME>
SHELL_NAME is replaced by the current shell name, such as Windows is generally conda init cmd
Linux: generally source activate
conda activate StreetFighterAI

update pip source

Original link: ubuntu replace pip source
temporarily use
pip3 install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install jupyter_contrib_nbextensions -i https://pypi.tuna.tsinghua.edu.cn/simple
replace pip source
Tsinghua: https://pypi.tuna.tsinghua.edu.cn/simple
Alibaba Cloud: https://mirrors.aliyun.com/pypi/simple
enter configuration (if not, create a new one first)
$ sudo mkdir ~/ pip
$ sudo gedit ~/pip/pip.conf
modify the content as follows:

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

Unable to write pip.conf error resolution

You can check the buftype settings with the following names. When buftype=nofile, the file cannot be saved. Only when buftype=null, it can be saved.

:verbose set buftype
1
The method of modifying buftype: switch vim to ex mode, input

:setlocal buftype=
1
If you want to return to the original setting, you can use the following command:

:setlocal buftype=nofile
1

Jupyter Notebook installation and configuration

install jupyter notebook

Execute four commands in sequence, the third command is to set the password
conda install jupyter notebook -y
jupyter notebook --generate-config
jupyter notebook password
password: set by yourself

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

Login without password

Edit jupyter_notebook_config.py:

cd ~/.jupyter/
gedit jupyter_notebook_config.py

Assign c.NotebookApp.token to a null value, ie:
c.NotebookApp.token = ''

Install ipykernel

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

Run Jupyter Notebook

Run:
$ The jupyter notebook
browser opens:
http://localhost:8888/
Enter the password to enter the environment normally.
insert image description here
Test code:
insert image description here

Code auto-completion extension

First install the extension library
pip install jupyter_contrib_nbextensions
jupyter contrib nbextensions install --user
pip install jupyter_nbextensions_configurator

After the installation is complete, restart Jupyter notebook,
click on the Nbextensions option, and check Hinterland

Tips: Linux restart command:

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命令取消关机

Guess you like

Origin blog.csdn.net/Medlar_CN/article/details/130255286