pytorch环境配置

1.查看已有的虚拟环境

conda env list

image

2.创建虚拟环境的名字和python版本

conda create -n nupack python=3.8

image

3.维基百科查看显卡算力以及对应的cuda版本

image

image

4.查看自己的cuda版本

image

5.找到pytorch历史版本安装代码

https://pytorch.org/get-started/previous-versions/

6.激活想要的虚拟环境并安装torch

image

# CUDA 11.6
pip install torch==1.13.0+cu116 torchvision==0.14.0+cu116 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu116

image

7.requirements.txt下载完后继续手动下载,conda失败后pip

image

pip install scikit_learn==1.1.2

image

8.jupyter报错

jupyter-notebook list

image

image

解决方案
https://github.com/jupyter/notebook/issues/2416

image
万分感谢

conda install jupyter notebook==5.7.10

image

success
image

有一些未清理的端口,清理掉
解决方案
https://github.com/jupyter/notebook/issues/2844
image
万分感谢!

image

清理成功
image

生成默认配置文件并修改

jupyter-notebook --generate-config

image

进入jupyter notebook新建后报错500

[E 22:12:49.132 NotebookApp] Uncaught exception GET /notebooks/%E8%BF%85%E9%9B%B7%E4%B8%8B%E8%BD%BD/%E7%A0%94%E7%A9%B6%E7%94%9F/%E7%A0%94%E4%B8%80%E4%B8%8B/dna/%E9%9A%8F%E6%9C%BA%E5%BA%8F%E5%88%97%E6%B1%A0%E4%B8%AD%E6%94%AF%E7%82%B9%E4%BB%8B%E5%AF%BC%E7%9A%84%E9%93%BE%E4%BD%8D%E7%A7%BB/randompooltmsd-master/NUPACK%20%20analysis%20and%20feature%20extraction/Untitled.ipynb?kernel_name=python3 (::1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/notebooks/%E8%BF%85%E9%9B%B7%E4%B8%8B%E8%BD%BD/%E7%A0%94%E7%A9%B6%E7%94%9F/%E7%A0%94%E4%B8%80%E4%B8%8B/dna/%E9%9A%8F%E6%9C%BA%E5%BA%8F%E5%88%97%E6%B1%A0%E4%B8%AD%E6%94%AF%E7%82%B9%E4%BB%8B%E5%AF%BC%E7%9A%84%E9%93%BE%E4%BD%8D%E7%A7%BB/randompooltmsd-master/NUPACK%20%20analysis%20and%20feature%20extraction/Untitled.ipynb?kernel_name=python3', version='HTTP/1.1', remote_ip='::1')
    Traceback (most recent call last):
      File "D:\Anaconda3\envs\nupack\lib\site-packages\tornado\web.py", line 1784, in _execute
        result = method(*self.path_args, **self.path_kwargs)
      File "D:\Anaconda3\envs\nupack\lib\site-packages\tornado\web.py", line 3290, in wrapper
        return method(self, *args, **kwargs)
      File "D:\Anaconda3\envs\nupack\lib\site-packages\notebook\notebook\handlers.py", line 90, in get
        self.write(self.render_template('notebook.html',
      File "D:\Anaconda3\envs\nupack\lib\site-packages\notebook\base\handlers.py", line 519, in render_template
        return template.render(**ns)
      File "D:\Anaconda3\envs\nupack\lib\site-packages\jinja2\environment.py", line 1301, in render
        self.environment.handle_exception()
      File "D:\Anaconda3\envs\nupack\lib\site-packages\jinja2\environment.py", line 936, in handle_exception
        raise rewrite_traceback_stack(source=source)
      File "D:\Anaconda3\envs\nupack\lib\site-packages\notebook\templates\notebook.html", line 1, in top-level template code
        {% extends "page.html" %}
      File "D:\Anaconda3\envs\nupack\lib\site-packages\notebook\templates\page.html", line 154, in top-level template code
        {% block header %}
      File "D:\Anaconda3\envs\nupack\lib\site-packages\notebook\templates\notebook.html", line 112, in block 'header'
        {% for exporter in get_frontend_exporters() %}
      File "D:\Anaconda3\envs\nupack\lib\site-packages\notebook\notebook\handlers.py", line 19, in get_frontend_exporters
        from nbconvert.exporters.base import get_export_names, get_exporter
      File "D:\Anaconda3\envs\nupack\lib\site-packages\nbconvert\__init__.py", line 4, in <module>
        from .exporters import *
      File "D:\Anaconda3\envs\nupack\lib\site-packages\nbconvert\exporters\__init__.py", line 3, in <module>
        from .html import HTMLExporter
      File "D:\Anaconda3\envs\nupack\lib\site-packages\nbconvert\exporters\html.py", line 12, in <module>
        from jinja2 import contextfilter
    ImportError: cannot import name 'contextfilter' from 'jinja2' (D:\Anaconda3\envs\nupack\lib\site-packages\jinja2\__init__.py)
[E 22:12:49.145 NotebookApp] {
      "Host": "localhost:8888",
      "Connection": "keep-alive",
      "Sec-Ch-Ua": "\"Google Chrome\";v=\"125\", \"Chromium\";v=\"125\", \"Not.A/Brand\";v=\"24\"",
      "Sec-Ch-Ua-Mobile": "?0",
      "Sec-Ch-Ua-Platform": "\"Windows\"",
      "Upgrade-Insecure-Requests": "1",
      "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
      "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
      "Sec-Fetch-Site": "same-origin",
      "Sec-Fetch-Mode": "navigate",
      "Sec-Fetch-Dest": "document",
      "Referer": "http://localhost:8888/tree/%E8%BF%85%E9%9B%B7%E4%B8%8B%E8%BD%BD/%E7%A0%94%E7%A9%B6%E7%94%9F/%E7%A0%94%E4%B8%80%E4%B8%8B/dna/%E9%9A%8F%E6%9C%BA%E5%BA%8F%E5%88%97%E6%B1%A0%E4%B8%AD%E6%94%AF%E7%82%B9%E4%BB%8B%E5%AF%BC%E7%9A%84%E9%93%BE%E4%BD%8D%E7%A7%BB/randompooltmsd-master/NUPACK%20%20analysis%20and%20feature%20extraction",
      "Accept-Encoding": "gzip, deflate, br, zstd",
      "Accept-Language": "zh-CN,zh;q=0.9",
      "Cookie": "_xsrf=2|ee88bb9d|c85276e4f2d8efd58b51eab6368e850f|1716637645; username-localhost-8888=\"2|1:0|10:1716646116|23:username-localhost-8888|44:N2I5OWU3YzQ2NTY1NDRhOWFjMTRiZTBmNGZiZDY4ZmQ=|3f8994d0d3f13f02c11540396ddd46fed778fbaec58176eb6832f2bc85a40a9e\""
    }
[E 22:12:49.145 NotebookApp] 500 GET /notebooks/%E8%BF%85%E9%9B%B7%E4%B8%8B%E8%BD%BD/%E7%A0%94%E7%A9%B6%E7%94%9F/%E7%A0%94%E4%B8%80%E4%B8%8B/dna/%E9%9A%8F%E6%9C%BA%E5%BA%8F%E5%88%97%E6%B1%A0%E4%B8%AD%E6%94%AF%E7%82%B9%E4%BB%8B%E5%AF%BC%E7%9A%84%E9%93%BE%E4%BD%8D%E7%A7%BB/randompooltmsd-master/NUPACK%20%20analysis%20and%20feature%20extraction/Untitled.ipynb?kernel_name=python3 (::1) 71.07ms referer=http://localhost:8888/tree/%E8%BF%85%E9%9B%B7%E4%B8%8B%E8%BD%BD/%E7%A0%94%E7%A9%B6%E7%94%9F/%E7%A0%94%E4%B8%80%E4%B8%8B/dna/%E9%9A%8F%E6%9C%BA%E5%BA%8F%E5%88%97%E6%B1%A0%E4%B8%AD%E6%94%AF%E7%82%B9%E4%BB%8B%E5%AF%BC%E7%9A%84%E9%93%BE%E4%BD%8D%E7%A7%BB/randompooltmsd-master/NUPACK%20%20analysis%20and%20feature%20extraction
[W 22:12:59.117 NotebookApp] Forbidden

解决方案https://github.com/d2l-ai/d2l-book/issues/46
image

jinjia2降低至3.0.3后解决
image
万分感谢

image

image

image

image

9.在jupyter里面激活我们的环境

首先在anaconda prompt里面激活我们需要的环境

python -m ipykernel install --name nupack

image

image

参考:https://devpress.csdn.net/xian/65ee75e758e03c66a1b55238.html?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MjIzNjYwNywiZXhwIjoxNzE3MjQxOTc3LCJpYXQiOjE3MTY2MzcxNzcsInVzZXJuYW1lIjoid2VpeGluXzUxNTk2Nzc0In0.9zulHmysmrRavgo6-cXh8hxnotu5DWwMFglZg1-fHls
万分感谢

10.在 Pycharm 里使用 Jupyter Notebook

image

Anaconda Prompt里输入jupyter notebnook
image
拷贝到配置里面去,成功
image

这样每次关闭后都要重新配置token,设置密码

jupyter notebook --generate-config

先关闭,找到配置路径。然后进入python


python

from notebook.auth import passwd
passwd()

image

密码不会显示,盲打就行,单引号里面的字符串复制到配置里面去(记得去注释)
image

Anaconda Prompt里打开jupyter notebnook,输入密码后不用每次配置啦

11.结尾的一些小插曲

必须先使用默认的python3环境,否则404报错。
image

参考链接
https://blog.csdn.net/qq_43426078/article/details/123106951
image

https://intellij-support.jetbrains.com/hc/en-us/community/posts/4410324715026-Erro-in-Jupyter-notebook-No-session-ID-specified

image
6
算了,又不是不能用

posted @ 2024-05-26 17:05  zuoyeb  阅读(471)  评论(0)    收藏  举报