After having the server's IP, port number, username, and password, how to run python on Ubuntu.
1 Access the remote server
First of all, in order to access the remote server, you can download the following two software:
Xshell
Xftp
2 Install Anaconda
Download the anaconda installation package from the Tsinghua University mirror station and upload it to the remote server.
Use the following statement in the folder where the installation package is located to install. If the anaconda file I downloaded is named ‘anaconda.sh’
bash anaconda.sh
Just follow the instructions to complete the installation.
After initializing conda, use the following statement to use the completed conda environment (after execution, (base) will be displayed at the far left of the command line)
source ~/.bashrc
If there is no .bashrc file, create a new .bashrc file.
vim ~/.bashrc
Enter the following content and change the path to your own anaconda path
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/lzztlb/guomingchao/software/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/lzztlb/guomingchao/software/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/lzztlb/guomingchao/software/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/lzztlb/guomingchao/software/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
To solve the problem, you need to enter the source ~/.bashrc command to display (base) every time you access it.
vim ~/.bash_profile 在文件内部输入 (新文件)
if [ -f ~/.bashrc ] ; then
source .bashrc
fi
3 Create a python environment
conda create --name your_env_name python=3.8.10
After installing the environment, you can enter the created python environment installation package, such as pytorch, etc.
conda activate your_env_name pip install your_package
Install ipykernel and configure the environment into jupyter notebook
pip install ipykernel python -m ipykernel install --user --name your_env_name
4 Configure Jupyter notebook
In the base environment, if you are not in the base environment, you can use the following statement to return to the base environment.
conda deactivate
Use the following statement to generate the jupyter notebook configuration file
jupyter notebook --generate-config
Use Xftp to open the configuration file 'jupyter_notebook_config.py' under the path /home/your_user_name/.jupyter, find the following statement and configure it, and cancel the previous comment symbol "#"
c.NotebookApp.ip='your_server_ip' c.NotebookApp.port =8888 c.NotebookApp.password = u'xxxxx-your password' c.NotebookApp.open_browser = False c.NotebookApp.notebook_dir = u'/home/xxx'
The password can be generated using the following statement in the terminal
ipython
from notebook.auth import passwd
passwd()
5 Remote access to Jupyter notebook via web page
Xshell accesses the server terminal, starts jupyter notebook and sets it to close the terminal and not terminate the process.
nohup jupyter notebook&
On your local computer, open the URL:
https://your_server_ip:port
You can also view the log file ‘nohup.out’ generated by the server to view the access URL of jupyter notebook.
After opening the URL, enter the previously set access password to access jupyter notebook.