SoFunction
Updated on 2024-11-12

anaconda3 installation and jupyter environment configuration of the full tutorial

1. Downloading

You can go to Tsinghua Source to download the latest version of the anaconda package, which is much faster than downloading it from the official website at the following address:

/anaconda/archive/

Scroll to the bottom of the page and download the latest version of Anaconda3-5.3.1-Linux-x86_64.sh.

wget /anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh

2. Installation

Use downline naming for installation:

sh ./Anaconda3-5.3.1-Linux-x86_64.sh

During installation, take care to specify the installation directory as /opt/anaconda3. It is possible to configure the installer directory without configuring it into the current user's .bashrc, as the local installation is configured directly in /etc/profile in order to make it available to multiple users.

3. Configuring environment variables

Edit /etc/profile for environment variable configuration:

vim ~/.bashrc

Copy all the naming below directly to the bottom of the file:

# added by Anaconda3 5.3.1 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/opt/anaconda3/bin/conda'  hook 2> /dev/null)"
if [ $? -eq 0 ]; then
 \eval "$__conda_setup"
else
 if [ -f "/opt/anaconda3/etc//" ]; then
 . "/opt/anaconda3/etc//"
 CONDA_CHANGEPS1=false conda activate base
 else
 \export PATH="/opt/anaconda3/bin:$PATH"
 fi
fi
unset __conda_setup
# <<< conda init <<<

Make the environment variable effective:

source ~/.bashrc

It is important to note that it is best not to configure the above commands directly into /etc/profile, as this will make anaconda available to all users, but it may have a negative impact on the system, e.g., by changing the beginning of the terminal command line to: (base) -bash-4.2#.

4. Creating user groups

If you don't create a user group for unified management of user rights, users other than the root user can also use the anaconda program, but when you create the environment, the virtual environments created will be back in the .conda in their home directories, which is inconvenient for unified management.

Create an anaconda user group, and then authorize the anaconda runtime program to this user group, and then add the users who need to execute the anaconda program to the anaconda user group so that all users can use the anaconda program, and all the virtual environments created are uniformly stored in the /opt/anaconda/ envs directory.

Create user groups:

sudo groupadd anaconda

Set the group /opt/anaconda3 belongs to to anaconda:.

sudo chgrp -R anaconda /opt/anaconda3

Modify directory permissions for /opt/anaconda3:

sudo chmod 770 -R /opt/anaconda3

Add system users who need to use the anaconda program to the anaconda user group:

sudo usermod -a -G anaconda user ID

5. Uninstalling anaconda

If you want to uninstall anaconda you can do so:

(1) Directly delete the installation directory /opt/anaconda3

rm -rf /opt/anaconda3

(2) Modify environment variables

Remove all configurations about anaconda from ~/.bashrc and /etc/profile, then execute the following line of code to make it take effect:

source ~/.bashrc

6. Update conda + install ipykernel

before proceeding with subsequent operations,Update firstconda,if not,The following anomalies may occur: Traceback (most recent call last): File "./conda", line 7, in <module> from import main ModuleNotFoundError: No module named 'conda' (base) [chb@chb-VMserver bin]$ conda Traceback (most recent call last): File "/opt/anaconda3/bin/conda", line 7, in <module> from import main ModuleNotFoundError: No module named 'conda' Use the following command to update:

conda update conda

Install ipykernel:

conda install ipykernel

7. kernel configuration:

Before configuring the virtual environments, you need to create kernel files for each virtual environment:

conda install -n Name of the environment ipykernel

For example to add a kernel file for a virtual environment named nlp: conda install -n nlp ipykernel

Go to the Python environment where the kernel needs to be added and write the configuration:

Note that you must first enter the Python environment in which you need to add the kernel, otherwise you will still be using the Python environment you are currently in, even though you have modified the kernel file for nlp that you created in step 7. The modification method is shown below:

conda activate nlp

python -m ipykernel install --user --name nlp --display-name "Natural Language Processing"

8. Configure jupyter lab

Production of encrypted passwords, this password applies to logging into jupyter lab when used to increase security, the subsequent configuration of jupyter lab to write the configuration documentation, here first create a good:

python -c "import IPython; print(())"

Generate the jupyter lab configuration file:

jupyter notebook --generate-config

The generated configuration file is saved in the current user's .jupyter directory. For example, if you run it under root, the generated configuration file is in /root/.jupyter/jupyter_notebook_config.py.

Modify the generated configuration file with the following changes:

.allow_remote_access = True # Allow remote access
 = '*'    # Allow any ip to access this server
 = 'sha1:xxx:xxx'  # The ciphertext generated in the previous step, note that the sha1 part cannot be missing.
.open_browser = False  # Run without opening the local browser
.allow_root =True   # Allow running with root privileges
 = 8888   # Specify the port used by jupyter notebook
.root_dir = '/jupyter' # Specify the directory where files such as ipynb are stored
.notebook_dir = '/jupyter'  # Job Catalog(Project root directory)

9. Install nodejs

jupyter in many features need nodejs support, such as plug-ins, we start before installing nodejs, to avoid the subsequent startup of the words in the emergence of no installation of nodejs and anomalies. Install nodejs command is as follows:

conda install nodejs

10. Start jupyter

The frontend runs:

jupyter lab

Running in the background:

nohup jupyter lab > /home/username/jupyter/ 2>&1 &

11. Plug-in installation

To open the plugin, click Settings->Advaned Settings Editor one at a time

After clicking on it, the following page appears, click Extension Manager, copy the content in the center to the right side, and change the value of enabled to true, as shown in the following figure:

Then press ctrl + S to save.

summarize

This article on the anaconda3 installation and jupyter environment configuration tutorial article is introduced to this, more related to anaconda3 installation and jupyter environment configuration content, please search for my previous posts or continue to browse the following related articles I hope that you will support me more in the future!