Home>
I want to solve

I'm making a LINE bot that scrapes with Python.
An error has occurred in the import of BeautifulSoup, and it cannot be resolved.
After examining various things, I think that the installed Python is different from the installed part, but as long as I examine it myself, it seems to match.

I would appreciate it if you could tell me the cause and how to investigate.
Windows10, the execution environment is heroku.

Error log Checking with

heroku logsshows the following log.

2019-11-19T15: 35: 15.021825 + 00: 00 app [web.1]: sys.version_info (major = 3, minor = 7, micro = 4, releaselevel = 'final', serial = 0)
2019-11-19T15: 35: 15.022294 + 00: 00 app [web.1]: Traceback (most recent call last):
2019-11-19T15: 35: 15.022301 + 00: 00 app [web.1]: File "main.py", line 16, in<module>
2019-11-19T15: 35: 15.022528 + 00: 00 app [web.1]: import scrape as sc
2019-11-19T15: 35: 15.022534 + 00: 00 app [web.1]: File "/app/scrape.py", line 4, in<module>
2019-11-19T15: 35: 15.022708 + 00: 00 app [web.1]: from bs4 import BeautifulSoup
2019-11-19T15: 35: 15.022762 + 00: 00 app [web.1]: ModuleNotFoundError: No module named 'bs4'
corresponding code

The import part of scrape.py is written as follows.

# for debugging
import sys
print (sys.version_info)
import urllib.request
from bs4 import BeautifulSoup
import json
import requests
  • Install BeautifulSoup
    Whenpip install beautifulsoupis executed, the following is displayed.
    I understand that the installation is complete.
Requirement already satisfied: beautifulsoup4 in c: \ pg \ python \ lib \ site-packages (4.8.1)
Requirement already satisfied: soupsieve>= 1.2 in c: \ pg \ python \ lib \ site-packages (from beautifulsoup4) (1.9.5)


There is certainly a bs4 folder under C: \ pg \ Python \ Lib \ site-packages.
I don't know where heroku's Python says it can't be found.

  • Change environment variables
    The system environment variable was changed and restarted as follows, but there was no change.
    PYTHONPATH C: \ pg \ Python \ Lib \ site-packages

  • Check reference path in interactive mode
    Execution command and execution result in interactive mode.

>>>import sys
>>>print (sys.path)
['', 'C: \\ pg \\ Python \\ Lib \\ site-packages',' C: \\ pg \\ Python \\ python37.zip ',' C: \\ pg \\ Python \\ DLLs', 'C: \\ pg \\ Python \\ lib', 'C: \\ pg \\ Python']
  • Try various other commands
    I tried it while referring to https://www.tutorialfor.com/go.php?id=64929 ,
    I did not understand the cause well.
    Tappython -c "import bs4"⇒ Nothing special

Thank you. .
Please let me know if there is any missing information.