首页 > 解决方案 > 共享 Jupyter 细胞

问题描述

除了pycharm之外,我终于开始使用jupyter notebook。但是,我发现从 jupyter 将代码粘贴到 stackoverflow 上更加麻烦。

我有以下错误


---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-78-9346139ce50d> in <module>
      1 blurred = cv2.medianBlur(img, 5)
----> 2 grey_blur = cv2.cvtColor(blurred, cv2.cv2.COLOR_BGR2GRAY)
      3 thresh = cv2.adaptiveThreshold(grey_blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 15, 5)
      4 combined = cv2.bitwise_and(new_image, new_image, mask=thresh)
      5 cv2.imshow("cartoon Lau blk shrt", combined)

error: OpenCV(4.5.3) c:\users\runneradmin\appdata\local\temp\pip-req-build-c2l3r8zm\opencv\modules\imgproc\src\color.simd_helpers.hpp:92: error: (-2:Unspecified error) in function '__cdecl cv::impl::`anonymous-namespace'::CvtHelper<struct cv::impl::`anonymous namespace'::Set<3,4,-1>,struct cv::impl::A0xb6623f80::Set<1,-1,-1>,struct cv::impl::A0xb6623f80::Set<0,2,5>,2>::CvtHelper(const class cv::_InputArray &,const class cv::_OutputArray &,int)'
> Invalid number of channels in input image:
>     'VScn::contains(scn)'
> where
>     'scn' is 1

除了报错信息,我想把整个代码贴出来,但是不想每个单元格都经过和crtl+c,crtl+v,好像过分了

我想尊重每个人在 stackoverflow 上的时间,并在理解最佳实践方面寻求帮助。

1-我听说从 VS Code 运行 jupyter 是一种选择,但还没有尝试过。

2-有没有办法直接从 jupyter 本身分享或者我应该查看 VS 代码?

3-也许还有另一个选项可以共享整个项目的链接


我已尝试下载 .py 文件。我能够将它拖到 PyCharm 中,但格式仍然关闭

# In[ ]:


image = cv2.imread('C:\\Users\\holli\\OneDrive\\Pictures\\python photos\\lau black short changing room, haair.jpg')
image.shape


# In[ ]:


x,y,z= image.shape


# In[ ]:


plt.imshow(image)

所以,在这一点上,我现在将坚持使用 PyCharm。

标签: pythonjupyter-notebookgoogle-colaboratory

解决方案


  1. 单击一个单元格以将其选中。

  2. Shift+单击另一个单元格以选择该单元格和其间的所有单元格。

  3. 按只是C复制单元格输入(这是一个 jupyter 快捷方式)。这应该适用于复制到其他笔记本中,您也可以其粘贴到任何其他编辑器或 Stack Overflow 帖子中。

我不知道复制单元格输出的特定方法。它是网络浏览器中的所有文本,因此常规方法可以正常工作。


推荐阅读