ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

python-anaconda cuda安装和jupyter notebook使用

python-anaconda cuda安装和jupyter notebook使用 概要windowspython快速下载PYTORCH下载地址ANACONDA1. 下载地址2. 安装后设置环境变量3. 配置源4. 内网配置代理5. 常用命令CUDA安装JUPYTER NOTEBOOKjupyter notebook安装jupyter notebook安装目录插件pip下载慢问题如何查看pip当前的路径如何查看pip当前的配置文件配置安装镜像的地址linux环境安装windowspython快速下载https://mirrors.tuna.tsinghua.edu.cn/python/3.12.10/PYTORCH下载地址https://pytorch.org/get-started/locally/ANACONDA1. 下载地址https://www.anaconda.com/products/distribution这里需要右键保存即可下载一直点击下一步安装完成。2. 安装后设置环境变量C:\ProgramData\Anaconda3C:\ProgramData\Anaconda3\ScriptsC:\ProgramData\Anaconda3\Library\binC:\ProgramData\Anaconda3\Library\mingw-w64\binC:\ProgramData\Anaconda3\Library\usr\bin如果是miniconda3环境变量是C:\ProgramData\miniconda3C:\ProgramData\miniconda3\ScriptsC:\ProgramData\miniconda3\Library\binC:\ProgramData\miniconda3\Library\mingw-w64\binC:\ProgramData\miniconda3\Library\usr\bin3. 配置源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/126359352JUPYTER NOTEBOOKjupyter 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-configwindows文件默认会在目录c:/users/mypc/jupyter\jupyter_notebook_config.pylinux文件默认会在目录~/.jupyter/jupyter_notebook_config.py或者/userxxxx/.jupyter/jupyter_notebook_config.py打开config文件编辑如下内容类似如下保存c.NotebookApp.ip*c.NotebookApp.passworduargon2:$argon2id$v19$m10240,t10,p8$TkrMEqNT7Hjcms5Lgt46Bg$8wQgGoxGNluYv1J7f49FtRSgZjwLu53cr9mF2xr8Ec.NotebookApp.allow_remote_accessTrue# 更改目录注意版本c.NotebookApp.notebook_dirD:\\jpdirnotebook6x版本c.NotebookApp.notebook_dir‪F:\jupyterdirnotebook7x版本anaconda命令行启动jupyter notebook启动启动端口以及token会有提示在jupyter notebook中启动的conda的base环境中如果要使用torch要么在base环境中安装要么要进行配置参考哔哩哔哩https://www.bilibili.com/video/BV1hE411t7RN?p2vd_sourcedf50a7aa820e2fe3209e1b5cb4fa3d53注意jupyter_notebook_config.py与jupyter_notebook_config.json其中json文件的优先级高于py文件因此发现有修改了密码不生效的场景可以检查下另外如果出现报错No module named ‘notebook.auth’请卸载掉notebook安装6.5.4的notebookjupyter 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\l8ccccwhere pipD:\pythonext\Python\Python313\Scripts\pip.exe如何查看pip当前的配置文件C:\Users\xxxpip config-v listForvariantglobal,willtryloading C:\ProgramData\pip\pip.iniForvariantuser,willtryloading C:\Users\xxx\pip\pip.iniForvariantuser,willtryloading C:\Users\xxx\AppData\Roaming\pip\pip.iniForvariantsite,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-urlhttps://mirrors.tools.huawei.com/pypi/simple global.timeout120global.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.confWindows路径为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:xxxxxproxy.aliyun.com:8080或者在执行如下命令C:\Users\222pip config set global.https-proxy http://333:33333!aaproxy.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(total0, connectNone, readNone, redirectNone, statusNone)) 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(hostmirrors.ustc.edu.cn, port443): 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 tornado6.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(total4, connectNone, readNone, redirectNone, statusNone)) 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:xxproxy.ali.com:8080pip config set global.http-proxy http://xx:xxproxy.ali.com:8080pip 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 21
返回列表