简体   繁体   English

在 Jupyter Notebook 中运行 Python 代码时出现问题:GoodReadsScraper

[英]Problem running Python code in Jupyter Notebook: GoodReadsScraper

I would like to start by letting you know that I am a layperson.我想首先让你知道我是一个外行。 I only started working with Python a few weeks ago, so I am new to this and am not yet familiar with quite a lot of the necessary terminology.我几周前才开始使用 Python,所以我是新手,还不熟悉很多必要的术语。 I would be very grateful for your help!我将非常感谢您的帮助!

I want to try out Omar Einea's Goodreads Reviews Scraper ( https://github.com/OmarEinea/GoodReadsScraper ).我想试用 Omar Einea 的 Goodreads Reviews Scraper ( https://github.com/OmarEinea/GoodReadsScraper )。 I followed his instructions and installed beautifulsoup4, langdetect, selenium and lxml using pip.我按照他的指示,使用 pip 安装了 beautifulsoup4、langdetect、selenium 和 lxml。 I copy-pasted part of his code from reviews.py to a Jupyter Notebook to test it out and ran the following cell:我将他的部分代码从 review.py 复制粘贴到 Jupyter Notebook 以对其进行测试并运行以下单元格:

from Tools import SafeThread
from bs4 import BeautifulSoup
from langdetect import detect
from Browser import Browser
from Writer import Writer

However, I got the following error:但是,我收到以下错误:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-4dc46ca353f6> in <module>
----> 1 from Tools import SafeThread
      2 from bs4 import BeautifulSoup
      3 from langdetect import detect
      4 from Browser import Browser
      5 from Writer import Writer

ImportError: cannot import name 'SafeThread' from 'Tools' (unknown location)

I thought that perhaps I had to install tools first, so I ran Python Code:我想也许我得先安装工具,所以我运行了Python代码:

pip install tools

in the command line, but I received the message that it had already been installed:在命令行中,但我收到了它已经安装的消息:

C:\Users\Lore>pip install Tools
Requirement already satisfied: Tools in c:\users\xxx\appdata\local\programs\python\python38-32\lib\site-packages (0.1.9)
Requirement already satisfied: pytils in c:\users\xxx\appdata\local\programs\python\python38-32\lib\site-packages (from Tools) (0.3)
Requirement already satisfied: six in c:\users\xxx\appdata\local\programs\python\python38-32\lib\site-packages (from Tools) (1.13.0)
Requirement already satisfied: lxml in c:\users\xxx\appdata\local\programs\python\python38-32\lib\site-packages (from Tools) (4.4.2)

Do you have any ideas on how I might be able to solve this problem?你对我如何解决这个问题有什么想法吗?

I also have another question.我还有一个问题。 So far I have only worked in/with jupyter notebooks.到目前为止,我只在 jupyter 笔记本中工作过。 Is there a better way/place to write and run my Python scripts/commands?有没有更好的方法/地方来编写和运行我的 Python 脚本/命令?

I tried running the entire code from "Reviews.py", by opening it in IDLE and clicking on "run", but that just gave me this:我尝试通过在 IDLE 中打开“Reviews.py”并单击“运行”来运行整个代码,但这只是给了我这个:

Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
======= RESTART: C:\Users\xxx\Desktop\GoodReadsScraper-master\Reviews.py ======
>>> 

Thank you in advance for your kind help and understanding!在此先感谢您的帮助和理解!

'Tools' being referenced in Review.py is this script called 'Tools' in the repository you reference . Review.py中引用的“工具”是您引用的存储库中名为“工具”的脚本

What you installed with pip install tools is something not related to that.您使用pip install tools安装的内容与此无关。 You can see it here .你可以在这里看到它。

You'd have an easier time if you download all the code in the repository and then try running things while your working directory is set to that directory.如果您下载存储库所有代码,然后在您的工作目录设置为该目录时尝试运行,您会更轻松。 In a notebook you can use pwd to print your working directory.在笔记本中,您可以使用pwd打印您的工作目录。 You can use %cd to change it.您可以使用%cd来更改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM