我得到这个错误-ModuleNotFoundError:当我运行git-push-heroku master时,没有名为"requests"的模块。它说我的requirements.txt中没有请求,但它显然在那里。我相信有些奇怪的事情正在发生,因为2captcha蟒蛇。关于如何解决这个错误,有什么想法吗?下面包括我的requirements.txt文件和错误日志。
Requirements.txt文件:
requests==2.25.1
2captcha-python==1.1.0
beautifulsoup4==4.9.3
bs4==0.0.1
cachetools==4.2.2
certifi==2021.5.30
chardet==4.0.0
df2gspread==1.0.4
google-api-python-client==1.6.7
google-auth==1.31.0
google-auth-oauthlib==0.4.4
gspread==3.7.0
httplib2==0.19.1
idna==2.10
lxml==4.6.3
numpy==1.20.3
oauth2client==4.1.3
oauthlib==3.1.1
pandas==1.2.4
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2021.1
requests-oauthlib==1.3.0
rsa==4.7.2
selenium==3.141.0
six==1.16.0
soupsieve==2.2.1
uritemplate==3.0.1
urllib3==1.26.5
错误日志:
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpacks:
remote: 1. heroku/python
remote: 2. https://github.com/heroku/heroku-buildpack-google-chrome
remote: 3. https://github.com/heroku/heroku-buildpack-chromedriver
remote: -----> Python app detected
remote: -----> No Python version was specified. Using the buildpack default: python-3.9.5
remote: To use a different version, see: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing python-3.9.5
remote: -----> Installing pip 20.2.4, setuptools 47.1.1 and wheel 0.36.2
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote: Collecting requests==2.25.1
remote: Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
remote: Collecting 2captcha-python==1.1.0
remote: Downloading 2captcha-python-1.1.0.tar.gz (8.8 kB)
remote: ERROR: Command errored out with exit status 1:
remote: command: /app/.heroku/python/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qcbdr2fk/2captcha-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-qcbdr2fk/2captcha-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-y8s7an11
remote: cwd: /tmp/pip-install-qcbdr2fk/2captcha-python/
remote: Complete output (9 lines):
remote: Traceback (most recent call last):
remote: File "<string>", line 1, in <module>
remote: File "/tmp/pip-install-qcbdr2fk/2captcha-python/setup.py", line 4, in <module>
remote: from twocaptcha import __version__
remote: File "/tmp/pip-install-qcbdr2fk/2captcha-python/twocaptcha/__init__.py", line 1, in <module>
remote: from .api import ApiClient
remote: File "/tmp/pip-install-qcbdr2fk/2captcha-python/twocaptcha/api.py", line 3, in <module>
remote: import requests
remote: ModuleNotFoundError: No module named 'requests'
remote: ----------------------------------------
remote: ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to python-selenium-southcarolina.
remote:
To https://git.heroku.com/python-selenium-southcarolina.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/python-selenium-southcarolina.git'
pip
首先下载所有模块,然后安装。因此,当pip
下载2captcha
时,则requests
已经下载但尚未安装。这就成了问题。
您必须首先安装除2captcha
之外的所有模块,然后只安装2captcha
。或者先只安装requests
,然后再安装其他模块。
编辑:
我不能测试它,但在文档中你可以看到它也可以使用setup.py
来安装模块。但我不知道它是同时运行setup.py
和requirements
,还是只运行其中一个。
在venv
的本地计算机上,我使用setup.py
安装了两者
from setuptools import setup
setup(
install_requires=['requests', 'wheel'],
)
import subprocess
subprocess.run('python -m pip install 2captcha-python', shell=True)
并运行python setup.py install
(但Heroku
应自动运行(
稍后刷新帐户时,我将在Heroku
上测试它。