四、配置过程中可能遇到的问题
1. 设置免密登录时没有 .ssh 的文件夹
① 创建目录 ~/.ssh 并设置权限
mkdir ~/.ssh
chmod 700 /root/.ssh
② 创建文件 ~/.ssh/authorized_keys
vim ~/.ssh/authorized_keys
该文件不存在,所以vim会自动创建。按一下字母"i"然后同时按shift + Insert 进行粘贴(或者单击鼠标右键即可),前提是已经复制到剪切板中了。粘贴好后。再按ESC,然后输入冒号wq 即 :wq 就保存了。
2. root用户使用pip安装提示‘中断’问题
WARNING: Running pip as the ‘root’ user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[参考]:https://blog.csdn.net/weixin_51080564/article/details/123584119
方案:创建一个虚拟目录
① 寻找pip位置
find / -name pip-*
首先我们需要找到我们的pip安装位置,然后cd过去在该路径执行以下命令
② 创建虚拟目录
python3 -m venv tutorial-env
- 不回显是正常的
- 回显,表示缺少python3-venv包,安装即可
apt install python3-venv
③ 激活
source tutorial-env/bin/activate
④ 更新pip
pip install --upgrade pip
3. root用户打开jupyter notebook 需要输入–allow-root
Running as root is not recommended. Use --allow-root to bypass.
① 生成配置文件
jupyter notebook --generate-config --allow-root
② 打开生成的配置文件
vim /root/.jupyter/jupyter_notebook_config.py
③ 找到如下行,去掉#,将False 改成True
#c.NotebookApp.allow_root = False
④ 重新运行jupuyer notebook
jupyter notebook
4. Nvidia 驱动不上
① 检查驱动型号
ls /usr/src | grep nvidia
> nvidia-515.65.01
② 重新安装
sudo apt install dkms
sudo dkms install -m nvidia -v 515.65.01
5. 文件传输
sudo apt install lrzsz
rz # windows-->linux
sz filename # linux-->windows
6. Pip源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
> http://mirrors.aliyun.com/pypi/simple/
> https://pypi.mirrors.ustc.edu.cn/simple/
> http://pypi.douban.com/simple/
7. 定时刷新
每隔2秒刷新一次,每次只在固定位置刷新
watch -n 2 -d nvidia-smi
8. 申请GPU主机
每隔2秒刷新一次,每次只在固定位置刷新
salloc -p gpu-rtx3090 --gres=gpu:1
squeue
scancel PID
sinfo
9. 将自己创建的环境添加到jupyterNotebook中
每隔2秒刷新一次,每次只在固定位置刷新
pip install ipykernel
python -m ipykernel install --name pyg
10. 将API key 保存到环境变量
- 设置环境变量(OPENAI_API_KEY, API_TOKEN(huggingface))
PowerShell
setx OPENAI_API_KEY "sk-ql*****************Yfe"
- 在python中使用环境变量
import os
openai_api_key = os.getenv("OPENAI_API_KEY")
print("OpenAI API Key:", openai_api_key)