Flask 不会在 PythonAnywhere 中使用我安装的模块

Flask Wont use my Installed Modules in PythonAnywhere

我需要帮助了解这里出了什么问题。

我会尽力解释这一点,但我对 PythonAnywhere 有点陌生。我收到此错误:

Traceback (most recent call last):
  File "/home/HelliottChip/mysite/app/__init__.py", line 6, in <module>
    from flask_migrate import Migrate
ModuleNotFoundError: No module named 'flask_migrate'

尝试 运行 我的 main.py 文件时。但是我已经安装了它们,如下代码所示:

17:14 ~/.local/bin $ pip install Flask-SQLAlchemy email_validator flask-mail pyjwt flask-bootstrap flask-moment                                                                                                  
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2
.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support                                                                      
Looking in links: /usr/share/pip-wheels                                                                                                                                                                          
Requirement already satisfied: Flask-SQLAlchemy in /usr/local/lib/python2.7/dist-packages (2.4.1)                                                                                                                
Requirement already satisfied: email_validator in /home/HelliottChip/.local/lib/python2.7/site-packages (1.1.2)                                                                                                  
Requirement already satisfied: flask-mail in /usr/local/lib/python2.7/dist-packages (0.9.1)                                                                                                                      
Requirement already satisfied: pyjwt in /usr/local/lib/python2.7/dist-packages (1.7.1)                                                                                                                           
Requirement already satisfied: flask-bootstrap in /usr/local/lib/python2.7/dist-packages (3.3.7.1)                                                                                                               
Requirement already satisfied: flask-moment in /home/HelliottChip/.local/lib/python2.7/site-packages (0.11.0)                                                                                                    
Requirement already satisfied: Flask>=0.10 in /usr/local/lib/python2.7/dist-packages (from Flask-SQLAlchemy) (1.1.1)                                                                                             
Requirement already satisfied: SQLAlchemy>=0.8.0 in /usr/local/lib/python2.7/dist-packages (from Flask-SQLAlchemy) (1.3.10)                                                                                      
Requirement already satisfied: idna>=2.0.0 in /usr/local/lib/python2.7/dist-packages (from email_validator) (2.8)                                                                                                
Requirement already satisfied: dnspython>=1.15.0 in /home/HelliottChip/.local/lib/python2.7/site-packages (from email_validator) (1.16.0)                                                                        
Requirement already satisfied: blinker in /usr/local/lib/python2.7/dist-packages (from flask-mail) (1.4)                                                                                                         
Requirement already satisfied: dominate in /usr/local/lib/python2.7/dist-packages (from flask-bootstrap) (2.4.0)                                                                                                 
Requirement already satisfied: visitor in /usr/local/lib/python2.7/dist-packages (from flask-bootstrap) (0.1.3)                                                                                                  
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (1.1.0)                                                                         
Requirement already satisfied: Jinja2>=2.10.1 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (2.10.3)                                                                            
Requirement already satisfied: click>=5.1 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (7.0)                                                                                   
Requirement already satisfied: Werkzeug>=0.15 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (0.16.0)                                                                            
Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python2.7/dist-packages (from Jinja2>=2.10.1->Flask>=0.10->Flask-SQLAlchemy) (0.23)  

我已经浏览了所有我能找到的关于如何解决这个问题的网站,但我迷路了。这是我在 Replit.com 上工作了一段时间的 Flask 应用程序,在转移到 PythonAnywhere 之前它运行良好。我一直在努力解决这个问题大约两周 ^~^ 但仍然没有运气。我用了很多 this guide 来帮助我,因为我也在练习我的网络部署技能。 (不需要判断我正在使用烧瓶 -3- 的事实)但是有人可以花时间帮助我吗?可以的话,万分感谢

检查您在 PythonAnywhere 上的网络应用程序是否被 Python 设置为 运行 2.7 -- 我看到您在 pip install 之外使用虚拟环境,默认情况下将为 Python 2.7 使用 pip,如您在输出中所见(顺便说一句,它不适用于 PythonAnywhere,您需要提供 --user 选项)。如果要在虚拟环境之外为不同版本的 Python 安装软件包,请使用 pipX.X install --user ...(其中 X.X 应替换为所需的 Python 版本)。另外,请记住每次更改设置时都要重新加载网络应用程序。如果您真的遇到困难,也许可以尝试联系 PythonAnywhere 支持 (support@pythonanywhere.com) 或使用他们的论坛?

你好@TutorialWarrior9776 我的建议是:

步骤 1: 安装虚拟环境,

pip install virtualenv

第 2 步: 创建环境

virtualenv -p python3.8 NAME_ENV

步骤 3: 激活 env 并安装 requirements.txt(本地机器生成的文件包含模块 flask_migrate)

source NAME_ENV/bin/active

pip install -r requirements.txt

步骤 4: 在 pythonanywhere 的 (web) 部分设置你的 env 路径,仅此而已;

https://help.pythonanywhere.com/pages/Virtualenvs/

(部分:第 3 步:配置您的应用程序以使用此 virtualenv)

希望对您有所帮助 ;)