无法导入 pytorch-lightning 即使已安装。

huangapple go评论107阅读模式
英文:

Can't import pytorch-lightning even though I've installed it

问题

我尝试重构我的Python代码以使用PyTorch-Lightning。但是,我遇到了一个问题,无法导入PyTorch-Lightning库。我收到以下错误:

  1. ModuleNotFoundError Traceback (most recent call last)
  2. Cell In[1], line 14
  3. 12 from fastai.vision.all import *
  4. 13 from ipywidgets import IntProgress
  5. ---> 14 import pytorch_lightning as pl
  6. ModuleNotFoundError: No module named 'pytorch_lightning'

在导入时找不到pytorch_lightning库。

我只有一个Python环境和内核(我在Visual Studio Code中使用Jupyter Notebook)。当我检查pip列表时,我得到以下输出:

  1. Package Version
  2. ------------------------ -------------
  3. ...
  4. pytorch-lightning 2.0.1
  5. ...

正如您所见,已经安装了PyTorch-Lightning库,但即使我卸载,重新安装最新版本,再通过GitHub存储库安装,进行更新,都无法解决问题。看起来有什么问题?

英文:

I tried to refactor my python code to use Pytorch-Lightning. However I've faced the problem that I can't import Pytorch-Lightning library. I get this error:

  1. ModuleNotFoundError Traceback (most recent call last)
  2. Cell In[1], line 14
  3. 12 from fastai.vision.all import *
  4. 13 from ipywidgets import IntProgress
  5. ---> 14 import pytorch_lightning as pl
  6. ModuleNotFoundError: No module named 'pytorch_lightning'

It doesn't see pytorch_lightning and lightning when importing.

I have only one python environment and kernel(I'm using Jupyter Notebook in Visual Studio Code).
When I check pip list, I get this output:

  1. Package Version
  2. ------------------------ -------------
  3. aiohttp 3.8.4
  4. aiosignal 1.3.1
  5. anyio 3.6.2
  6. apturl 0.5.2
  7. arrow 1.2.3
  8. async-timeout 4.0.2
  9. attrs 22.2.0
  10. Automat 0.8.0
  11. backcall 0.1.0
  12. bcrypt 3.1.7
  13. beautifulsoup4 4.12.0
  14. bleach 3.1.1
  15. blessed 1.20.0
  16. blinker 1.4
  17. Brlapi 0.7.0
  18. certifi 2022.12.7
  19. chardet 3.0.4
  20. charset-normalizer 3.1.0
  21. Click 7.0
  22. cloud-init 22.4.2
  23. cmake 3.26.1
  24. colorama 0.4.3
  25. command-not-found 0.3
  26. configobj 5.0.6
  27. constantly 15.1.0
  28. croniter 1.3.8
  29. cryptography 2.8
  30. cupshelpers 1.0
  31. dateutils 0.6.12
  32. dbus-python 1.2.16
  33. decorator 4.4.2
  34. deepdiff 6.3.0
  35. defer 1.0.6
  36. defusedxml 0.6.0
  37. distro 1.4.0
  38. distro-info 0.23ubuntu1
  39. dnspython 2.3.0
  40. duplicity 0.8.12.0
  41. email-validator 1.3.1
  42. entrypoints 0.3
  43. fastapi 0.88.0
  44. fasteners 0.14.1
  45. filelock 3.11.0
  46. frozenlist 1.3.3
  47. fsspec 2023.4.0
  48. future 0.18.2
  49. h11 0.14.0
  50. html5lib 1.0.1
  51. httpcore 0.16.3
  52. httplib2 0.14.0
  53. httptools 0.5.0
  54. httpx 0.23.3
  55. hyperlink 19.0.0
  56. idna 3.4
  57. importlib-metadata 1.5.0
  58. incremental 16.10.1
  59. inquirer 3.1.3
  60. install 1.3.5
  61. ipykernel 5.2.0
  62. ipython 7.13.0
  63. ipython_genutils 0.2.0
  64. ipywidgets 6.0.0
  65. itsdangerous 2.1.2
  66. jedi 0.15.2
  67. Jinja2 3.1.2
  68. jsonpatch 1.22
  69. jsonpointer 2.0
  70. jsonschema 3.2.0
  71. jupyter-client 6.1.2
  72. jupyter-core 4.6.3
  73. keyring 18.0.1
  74. language-selector 0.1
  75. launchpadlib 1.10.13
  76. lazr.restfulclient 0.14.2
  77. lazr.uri 1.0.3
  78. lightning 2.1.0.dev0
  79. lightning-cloud 0.5.32
  80. lightning-utilities 0.8.0
  81. lit 16.0.0
  82. lockfile 0.12.2
  83. louis 3.12.0
  84. macaroonbakery 1.3.1
  85. Mako 1.1.0
  86. markdown-it-py 2.2.0
  87. MarkupSafe 2.1.2
  88. mdurl 0.1.2
  89. mistune 0.8.4
  90. monotonic 1.5
  91. more-itertools 4.2.0
  92. mpmath 1.3.0
  93. multidict 6.0.4
  94. nbconvert 5.6.1
  95. nbformat 5.0.4
  96. netifaces 0.10.4
  97. networkx 3.1
  98. notebook 6.0.3
  99. numpy 1.24.2
  100. nvidia-cublas-cu11 11.10.3.66
  101. nvidia-cuda-cupti-cu11 11.7.101
  102. nvidia-cuda-nvrtc-cu11 11.7.99
  103. nvidia-cuda-runtime-cu11 11.7.99
  104. nvidia-cudnn-cu11 8.5.0.96
  105. nvidia-cufft-cu11 10.9.0.58
  106. nvidia-curand-cu11 10.2.10.91
  107. nvidia-cusolver-cu11 11.4.0.1
  108. nvidia-cusparse-cu11 11.7.4.91
  109. nvidia-nccl-cu11 2.14.3
  110. nvidia-nvtx-cu11 11.7.91
  111. oauthlib 3.1.0
  112. olefile 0.46
  113. ordered-set 4.1.0
  114. orjson 3.8.9
  115. packaging 23.0
  116. pandocfilters 1.4.2
  117. paramiko 2.6.0
  118. parso 0.5.2
  119. pexpect 4.6.0
  120. pickleshare 0.7.5
  121. Pillow 7.0.0
  122. pip 23.0.1
  123. prometheus-client 0.7.1
  124. prompt-toolkit 2.0.10
  125. protobuf 3.6.1
  126. psutil 5.9.4
  127. pyasn1 0.4.2
  128. pyasn1-modules 0.2.1
  129. pycairo 1.16.2
  130. pycups 1.9.73
  131. pydantic 1.10.7
  132. Pygments 2.14.0
  133. PyGObject 3.36.0
  134. PyHamcrest 1.9.0
  135. PyJWT 1.7.1
  136. pymacaroons 0.13.0
  137. PyNaCl 1.3.0
  138. pyOpenSSL 19.0.0
  139. pyprof2calltree 1.4.4
  140. pyRFC3339 1.1
  141. pyrsistent 0.15.5
  142. pyserial 3.4
  143. python-apt 2.0.1
  144. python-dateutil 2.8.2
  145. python-debian 0.1.36ubuntu1
  146. python-dotenv 1.0.0
  147. python-editor 1.0.4
  148. python-multipart 0.0.6
  149. pytorch-lightning 2.0.1
  150. pytz 2019.3
  151. pyxdg 0.26
  152. PyYAML 6.0
  153. pyzmq 18.1.1
  154. ranger-fm 1.9.3
  155. readchar 4.0.5
  156. reportlab 3.5.34
  157. requests 2.28.2
  158. requests-unixsocket 0.2.0
  159. rfc3986 1.5.0
  160. rich 13.3.3
  161. screen-resolution-extra 0.0.0
  162. SecretStorage 2.3.1
  163. Send2Trash 1.5.0
  164. service-identity 18.1.0
  165. setuptools 67.6.1
  166. simplejson 3.16.0
  167. six 1.14.0
  168. sniffio 1.3.0
  169. sos 4.4
  170. soupsieve 2.4
  171. ssh-import-id 5.10
  172. starlette 0.22.0
  173. starsessions 1.3.0
  174. sympy 1.11.1
  175. systemd-python 234
  176. terminado 0.8.2
  177. testpath 0.4.4
  178. torch 2.0.0
  179. torchmetrics 0.11.4
  180. tornado 5.1.1
  181. tqdm 4.65.0
  182. traitlets 5.9.0
  183. triton 2.0.0
  184. Twisted 18.9.0
  185. typing_extensions 4.5.0
  186. ubuntu-advantage-tools 8001
  187. ubuntu-drivers-common 0.0.0
  188. ufw 0.36
  189. ujson 5.7.0
  190. unattended-upgrades 0.1
  191. urllib3 1.26.15
  192. usb-creator 0.3.7
  193. uvicorn 0.21.1
  194. uvloop 0.17.0
  195. wadllib 1.3.3
  196. watchfiles 0.19.0
  197. wcwidth 0.1.8
  198. webencodings 0.5.1
  199. websocket-client 1.5.1
  200. websockets 10.4
  201. wheel 0.40.0
  202. widgetsnbextension 2.0.0
  203. xkit 0.0.0
  204. yarl 1.8.2
  205. zipp 1.0.0
  206. zope.interface 4.7.1

As you can see, there is a Pytorch-Lightning library installed, however even when I uninstall, reinstall with newest version, install again through GitHub repository, updated, nothing works. What seems to be a problem?

答案1

得分: 1

最新版本的 pl API 已经发生了变化。
你可以尝试:

  1. import lightning as pl
英文:

The API of newest version of pl has been changed.
You can try:

  1. import lightning as pl

答案2

得分: 0

使用PyTorch Lightning 2.0的正确导入方式是 -

  1. import lightning L
  2. class Model(L.LightningModule):
  3. ...
  4. trainer = L.Trainer(max_epochs=1)
  5. trainer.fit(Model(), dataloader)

我们还发布了一个升级指南,链接在这里:1

英文:

moving forward with PyTorch Lightning 2.0, correct way to import is -

  1. import lightning L
  2. class Model(L.LightningModule):
  3. ...
  4. trainer = L.Trainer(max_epochs=1)
  5. trainer.fit(Model(), dataloader)

We also published an upgrade guide here

huangapple
  • 本文由 发表于 2023年4月11日 02:01:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75979522.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定