概要
- windows
- python快速下载
- PYTORCH下载地址
- ANACONDA
- 1. 下载地址
- 2. 安装后设置环境变量
- 3. 配置源
- 4. 内网配置代理
- 5. 常用命令
- CUDA安装
- JUPYTER NOTEBOOK
- jupyter notebook安装
- jupyter notebook安装目录插件
- pip下载慢问题
- 如何查看pip当前的路径
- 如何查看pip当前的配置文件
- 配置安装镜像的地址
- linux环境安装
windows
python快速下载
https://mirrors.tuna.tsinghua.edu.cn/python/3.12.10/
PYTORCH下载地址
https://pytorch.org/get-started/locally/
ANACONDA
1. 下载地址
https://www.anaconda.com/products/distribution
这里需要右键保存即可下载
一直点击下一步安装完成。
2. 安装后设置环境变量
C:\ProgramData\Anaconda3
C:\ProgramData\Anaconda3\Scripts
C:\ProgramData\Anaconda3\Library\bin
C:\ProgramData\Anaconda3\Library\mingw-w64\bin
C:\ProgramData\Anaconda3\Library\usr\bin
如果是miniconda3,环境变量是
C:\ProgramData\miniconda3
C:\ProgramData\miniconda3\Scripts
C:\ProgramData\miniconda3\Library\bin
C:\ProgramData\miniconda3\Library\mingw-w64\bin
C:\ProgramData\miniconda3\Library\usr\bin
3. 配置源
conda config --set show_channel_urls yes
C:\Users\Administrator.condarc
修改内容
channels: - defaults show_channel_urls: true default_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud或者
channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/ show_channel_urls: true ssl_verify: false或者直接使用命令
# 清除所有频道 conda config--remove-key channels # 添加清华源 conda config--add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/conda config--add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/conda config--add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/# 设置显示频道URL conda config--set show_channel_urls yes # 可选:添加conda-forge conda config--add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/4. 内网配置代理
C:\Users\Administrator.condarc中增加如下内容:
proxy_servers:http:http://xxxx:Li!@proxynj.45.com:8080https:http://xxxx:Li!@proxynj.34566.com:8080ssl_verify:false5. 常用命令
环境管理: conda create--name myenv:创建一个名为myenv的新环境。 conda init:执行activate前需要执行 conda activate myenv:激活名为myenv的虚拟环境。 conda deactivate:关闭当前激活的虚拟环境。 conda envlist:列出所有已创建的环境。 conda env export--name myenv--fileenvironment.yaml:导出名为myenv的环境配置到environment.yaml文件。 conda env create--fileenvironment.yaml:根据environment.yaml文件创建一个新环境。 conda remove--name EV--all:删除名为EV的环境及其所有包。 包管理: condalist:查看当前环境中已安装的包。 conda search xxxx:搜索名为xxxx的包。 conda install xxxx:在当前环境中安装名为xxxx的包。 conda install-n EV xxxx:在名为EV的环境中安装名为xxxx的包。 conda update xxxx:更新名为xxxx的包到最新版本。(如升级python版本) conda remove xxxx:从当前环境中删除名为xxxx的包。 配置管理: conda config--add channels 通道名称:向配置中添加一个新的通道。 conda config--remove channels 通道名称:从配置中移除指定的通道。 conda config--get channels:列出当前配置中所有配置的通道。 conda config--remove-key 配置项:重置指定配置项的值为默认值。 conda config--edit:打开配置文件以进行手动编辑。 更新和升级: conda update conda:更新conda到最新版本。 conda update anaconda:更新Anaconda及其相关组件到最新版本。 conda update python:更新Python到最新版本。CUDA安装
https://blog.csdn.net/weixin_44189155/article/details/126359352
JUPYTER NOTEBOOK
jupyter notebook安装
- 打开anaconda的命令提示行或者执行执行pip install jupyter
- 输入命令,并设定密码,使用u+生产的密码即可
#如果没有ipython,请使用pip install ipython $ ipython from notebook.authimportpasswdpasswd()#不使用ipython python from notebook.authimportpasswdpasswd()#注意 有的生成的是sha1,有的生成的是argon2(单引号全部在内都复制下来),都是可以的,记得前面加u- 记住生成的密码
- 退出ipython,生成配置文件
jupyter notebook --generate-config
windows文件默认会在目录:c:/users/mypc/jupyter\jupyter_notebook_config.py
linux文件默认会在目录:~/.jupyter/jupyter_notebook_config.py或者/userxxxx/.jupyter/jupyter_notebook_config.py
- 打开config文件,编辑如下内容,类似如下,保存
c.NotebookApp.ip='*'c.NotebookApp.password=u'argon2:$argon2id$v=19$m=10240,t=10,p=8$TkrMEqNT7Hjcms5Lgt46Bg$8wQgGoxGNluYv1J7f+49+FtRSgZjwLu53cr9mF2xr8E'c.NotebookApp.allow_remote_access=True# 更改目录,注意版本c.NotebookApp.notebook_dir="D:\\jpdir"(notebook6x版本)c.NotebookApp.notebook_dir="F:\jupyterdir"(notebook7x版本)- anaconda命令行启动jupyter notebook启动,启动端口以及token会有提示
- 在jupyter notebook中启动的conda的base环境中,如果要使用torch,要么在base环境中安装,要么要进行配置参考哔哩哔哩https://www.bilibili.com/video/BV1hE411t7RN?p=2&vd_source=df50a7aa820e2fe3209e1b5cb4fa3d53
- 注意
jupyter_notebook_config.py与jupyter_notebook_config.json,其中json文件的优先级高于py文件
因此,发现有修改了密码不生效的场景,可以检查下
另外,如果出现报错No module named ‘notebook.auth’,请卸载掉notebook,安装6.5.4的notebook
jupyter notebook安装目录插件
- 安装
pip install jupyter_contrib_nbextensions--trusted-host mirrors.tools.huawei.com-i http://mirrors.tools.huawei.com/pypi/simplejupyter contrib nbextension install--user重启jupyter notebook
重启后,tab里面就多了一项选择Table of Contents
然后打开文件就可以看到目录了
pip下载慢问题
pip语句结束后边加上: -i https://pypi.tuna.tsinghua.edu.cn/simple
(注意-i前面有个空格)
常用的源有:
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/ (这个感觉不错)
清华:https://pypi.tuna.tsinghua.edu.cn/simple
百度:https://mirror.baidu.com/pypi/simple
如何查看pip当前的路径
C:\Users\l8cccc>where pipD:\pythonext\Python\Python313\Scripts\pip.exe如何查看pip当前的配置文件
C:\Users\xxx>pip config-v listForvariant'global',willtryloading 'C:\ProgramData\pip\pip.ini'Forvariant'user',willtryloading 'C:\Users\xxx\pip\pip.ini'Forvariant'user',willtryloading 'C:\Users\xxx\AppData\Roaming\pip\pip.ini'Forvariant'site',willtryloading 'D:\pythonext\Python\Python313\pip.ini' global.extra-index-url='\nhttps://pypi.doubanio.com/simple/\nhttps://pypi.org/simple/\nhttps://mirrors.aliyun.com/pypi/simple/\nhttps://pypi.doubanio.com/simple/\nhttps://pypi.tuna.tsinghua.edu.cn/simple\nhttps://pypi.mirrors.ustc.edu.cn/simple/' global.index-url='https://mirrors.tools.huawei.com/pypi/simple' global.timeout='120'global.trusted-host='\nmirrors.aliyun.com\npypi.doubanio.com\npypi.org\nmirrors.tools.huawei.com\npypi.tuna.tsinghua.edu.cn\npypi.mirrors.ustc.edu.cn'或者
PSC:\Users\xx> pip config debug env_var: env: global: C:\ProgramData\pip\pip.ini,exists: False site: d:\python38\pip.ini,exists: False user: C:\Users\xx\pip\pip.ini,exists: False C:\Users\xx\AppData\Roaming\pip\pip.ini,exists: True global.index-url: https://mirrors.tools.huawei.com/pypi/simple global.timeout: 120 global.extra-index-url: https://pypi.doubanio.com/simple/ https://pypi.org/simple/ https://mirrors.aliyun.com/pypi/simple/ https://pypi.doubanio.com/simple/ https://pypi.tuna.tsinghua.edu.cn/simple https://pypi.mirrors.ustc.edu.cn/simple/说明生效的配置文件在C:\Users\xx\AppData\Roaming\pip\pip.ini
配置安装镜像的地址
- 临时(如果报错ProxyError(‘Cannot connect to proxy.’, timeout,可以尝试下面1的方法)
pip install --trusted-host mirrors.tools.aliyun.com -i https://mirrors.tools.aliyun.com/pypi/simple xxx - 永久
Pip的配置文件(如果没有该文件,可以手动创建)为用户根目录下的:~/.pip/pip.conf(Windows路径为:C:\Users\<UserName>\pip\pip.ini), 您可以配置如下内容: [global] index-url = https://mirrors.tools.huawei.com/pypi/simple timeout = 120 extra-index-url = https://pypi.doubanio.com/simple/ https://pypi.org/simple/ https://mirrors.aliyun.com/pypi/simple/ https://pypi.doubanio.com/simple/ https://pypi.tuna.tsinghua.edu.cn/simple https://pypi.mirrors.ustc.edu.cn/simple/ trusted-host = mirrors.aliyun.com pypi.doubanio.com pypi.org mirrors.tools.huawei.com pypi.tuna.tsinghua.edu.cn pypi.mirrors.ustc.edu.cn proxy = http://xxxx:xxxxx@proxy.aliyun.com:8080或者在执行如下命令
C:\Users\222>pip config set global.https-proxy http://333:33333!aa@proxy.333.com:8080
会自动生成如下路径,将上面的内容复制到下面文件就可以了
Writing to C:\Users\222\AppData\Roaming\pip\pip.ini
在安装的时候,可以能会出现如下提示,但是不要急着退出,让它继续跑,后面会正常下载。
ror(SSLCertVerificationError(1,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1125)'))': /pypi/simple/tornado/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1125)'))': /pypi/simple/tornado/ Could not fetch URL https://pypi.mirrors.ustc.edu.cn/simple/tornado/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='mirrors.ustc.edu.cn', port=443): Max retries exceeded with url: /pypi/simple/tornado/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED]certificate verify failed: self signed certificateincertificate chain(_ssl.c:1125)'))) - skipping Collecting tornado>=6.2.0 (from notebook) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/61/cc/58b1adeb1bb46228442081e746fcdbc4540905c87e8add7c277540934edb/tornado-6.4.2-cp38-abi3-win_amd64.whl (438 kB) WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 504 Gateway Time-out'))': /pypi/simple/anyio/- pip设置代理
pip config set global.https-proxy http://xx:xx@proxy.ali.com:8080
pip config set global.http-proxy http://xx:xx@proxy.ali.com:8080
pip config list 查看是否上设置成功
- 需要注意的事情
如果是powershell执行pip安装,如果有特殊字符,不需要转义。CMD需要转义。
linux环境安装
下载地址
https://repo.anaconda.com/archive/
设置包可执行
chmod +x
安装./anaxxxx.sh
安装完成后询问你是否需要将环境变量加入到.bashrc,输入yes
然后source bashrc
执行conda即可
使用jupyter notebook参照windows
补充:jupyter notebook 后台运行 nohup jupyter notebook --allow-root > jupyter.log 2>&1 &