Comments (71)
我尝试着简单部署到aws ec2 ubuntu上 我运行flask run出现了下面问题,我没有用venv环境。我需要修改哪些地方啊。
flask run
Usage: flask run [OPTIONS]
Error: Could not locate Flask application. You did not provide the FLASK_APP environment variable.
For more information see http://flask.pocoo.org/docs/latest/quickstart/
我是通过pycharm上传的 我在ubuntu 根目录建了一个项目文件夹,然后上传blogin文件的这个项目文件夹下面。
from blogin.
在项目根目录新建.flaskenv文件,在其中输入以下内容
FLASK_APP=blogin
FLASK_ENV=production
from blogin.
我把以前的development哪个删除了,写了以下的。
$ nano .flaskenv
GNU nano 2.9.3 .flaskenv
FLASK_APP=blogin
FLASK_ENV=production
还是老问题
flask run
Usage: flask run [OPTIONS]
Error: Could not locate Flask application. You did not provide the FLASK_APP environment variable.
For more information see http://flask.pocoo.org/docs/latest/quickstart/
from blogin.
我在terminal设置了 export FLASK_APP=blogin
flask run
Usage: flask run [OPTIONS]
Error: The file/path provided (blogin) does not appear to exist. Please verify the path is correct. If app is not on PYTHONPATH, ensure the extension is .py
from blogin.
用虚拟环境试下
cd Blogin
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
flask run
from blogin.
还有看看有没有安装python-dotenv
这个库
from blogin.
@weijiang1994 安装好python-dotenv 有这个错误。
flask run
- Serving Flask app 'blogin' (lazy loading)
- Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead. - Debug mode: off
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.
Error: While importing 'blogin', an ImportError was raised.
from blogin.
看看运行flask run
的执行路径是否有误。
from blogin.
@weijiang1994
我运行flask run就是上面的哪个错误
Error: While importing 'blogin', an ImportError was raised.
执行路径是否有误。--->执行路径啥意思
from blogin.
就是你是不是在Blogin文件夹下面执行的flask run
from blogin.
@weijiang1994 我是在Blogin文件夹下面 不过这个文件夹是我ubuntu建的,因为pycharm上传的时候 好像只是把local里的Blogin里的所有文件全部上传,并没有上传文件夹Blogin。所以我在ec2 ubuntu重新建了一个Blogin文件夹。然后local直接把Blogin里python文件上传上去。
from blogin.
建议用git
操作,你不是fork
了我的仓库吗,你把你的修改提交到你fork的远程仓库中去,然后在云服务器上直接git clone
你的代码
from blogin.
好的 我也试试。我想知道啥原因导致运行不行
from blogin.
试了git clone的方法 ubuntu服务器 同样的错误
from blogin.
信任我的话,可以把你aws服务器的 IP 登录名 登录密码
发我邮箱 [email protected],我帮你部署
from blogin.
@weijiang1994 可以啦 gitclone后,建立。flaskenv文件。我把production改成development。 很感谢你的热情。
刚开始的时候production
- Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
from blogin.
flask run
- Serving Flask app "blogin" (lazy loading)
- Environment: development
- Debug mode: on
- Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
- Restarting with stat
- Debugger is active!
- Debugger PIN: 985-679-113
from blogin.
ok
from blogin.
@weijiang1994 flask run运行后,我想打开aws url地址看看像local那样。 但是打开就是错误。
浏览器不能连接到服务器。我昨天测试简单的flask app是可以的
from blogin.
flask run --host=0.0.0.0
from blogin.
我运行啦 还是这样的问题
flask run --host=0.0.0.0
- Serving Flask app "blogin" (lazy loading)
- Environment: development
- Debug mode: on
- Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
- Restarting with stat
- Debugger is active!
- Debugger PIN: 985-679-113
from blogin.
亚马逊服务器IP多少?
from blogin.
52.197.136.131
from blogin.
from blogin.
是这个 我也ping不成功
from blogin.
是不是要把上次测试flask的log删除掉啊, 那个简单的测试app
from blogin.
ping不通说明你服务器有问题,跟这个没啥关系。你买的亚马逊哪个地区的?ping不通可能是国内防火墙把这个IP屏蔽掉了。
from blogin.
我买的tokyo地区
from blogin.
那国内大概率裸连不上,国内的腾讯云也不错,为什么要买亚马逊的呢...
from blogin.
from blogin.
不是买 可以免费用一年
from blogin.
腾讯云新用户也很便宜的,可以看看双十一的活动
from blogin.
@weijiang1994 好的。 你这个是app.run(host="0.0.0.0", port=80)在哪里
可能是不是端口的关系
from blogin.
@weijiang1994 刚关掉。flask run后上面问题又出现啦
flask run
- Serving Flask app 'blogin' (lazy loading)
- Environment: development
- Debug mode: on
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.
Error: While importing 'blogin.blogin', an ImportError was raised.
from blogin.
应该是你的项目结构路径有问题我从来没有遇到过这种问题
from blogin.
没解决的话,可以把你服务器登录的相关信息发我邮箱,我可以登录帮你看一下。
from blogin.
@weijiang1994 我过几天再试试 不行再找你。
from blogin.
@weijiang1994 我在服务器测试简单程序的flask run可以啊 为啥在 blogin说有问题啊
我想问一下 你程序里application.run(host='0.0.0.0') 在哪个python文件里?
为啥这里是
FLASK_APP=blogin
FLASK_ENV=development
我看很多都是FLASK_APP=xx.py
from blogin.
@weijiang1994 是不是这个文章的原因 https://zhuanlan.zhihu.com/p/128977263
from blogin.
@weijiang1994 刚才执行以下 chmod 777 .env 成功了一次 ,但是运行停止后 重亲来flask run就又是同样的问题
from blogin.
@weijiang1994 现在flask run OK啦
flask run
- Serving Flask app "blogin" (lazy loading)
- Environment: development
- Debug mode: on
- Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
- Restarting with stat
- Debugger is active!
- Debugger PIN: 202-159-839
但是我发现并没有启动程序像local那样
flask run
- Serving Flask app "blogin" (lazy loading)
- Environment: development
- Debug mode: on
- Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
- Restarting with fsevents reloader
- Debugger is active!
- Debugger PIN: 296-340-162
I am here
[2021-10-24 17:20:44,014] DEBUG in init: Scheduler Started,---------------
但是我发现了一个问题 每次我安装好一个package后, 比如flask_caching
flask run 又出现上面的错误
但是当我重新又pip3 install -r requirments.txt
我发现flask run可以 不过跟上面一样 没有启动像lcoal那样。
from blogin.
@weijiang1994 现在可以像local那样运行啦。但是页面说无法连接到服务器
from blogin.
Job "network_monitor (trigger: interval[0:01:00], next run at: 2021-10-24 09:12:02 UTC)" raised an exception
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/apscheduler/executors/base.py", line 125, in run_job
retval = job.func(*job.args, **job.kwargs)
File "/home/ubuntu/SciSci/blogin/task.py", line 160, in network_monitor
with open('/var/log/nginx/access.log', 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/var/log/nginx/access.log'
Job "network_monitor (trigger: interval[0:01:00], next run at: 2021-10-24 09:12:02 UTC)" raised an exception
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/apscheduler/executors/base.py", line 125, in run_job
retval = job.func(*job.args, **job.kwargs)
File "/home/ubuntu/SciSci/blogin/task.py", line 160, in network_monitor
with open('/var/log/nginx/access.log', 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/var/log/nginx/access.log'
from blogin.
我想问一下 在服务器上没有用nginx部署 ,你的程序仅仅用flask run后 通过ip地址是可以访问的吧?
from blogin.
240-215.ap-northeast-1.compute.amazonaws.com 拒绝了我们的连接请求。
请试试以下办法:
from blogin.
可以通过IP地址访问,但是你得确定你得IP地址能被国内访问到。
from blogin.
现在打开后出现了
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1698, "Access denied for user 'root'@'localhost'")
(Background on this error at: http://sqlalche.me/e/13/e3q8)
from blogin.
数据库连接用户名、密码错了...
from blogin.
@weijiang1994 show tables 咋是空的啊 我运行了flask db init啦
from blogin.
use blog;
Database changed
mysql>
mysql> show tables;
Empty set (0.00 sec)
from blogin.
flask db init
0: here is begin
I am here
[2021-10-24 12:17:31,554] DEBUG in init: Scheduler Started,---------------
Error: Directory migrations already exists and is not empty
from blogin.
from blogin.
@weijiang1994 flask initdb
File "/home/ubuntu/.local/lib/python3.6/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1698, "Access denied for user 'root'@'localhost'")
(Background on this error at: http://sqlalche.me/e/13/e3q8)
from blogin.
这不是跟上面的错误一样?数据库连接配置改了啊
from blogin.
@weijiang1994 OK啦
sudo mysql -u root # I had to use "sudo" since it was new installation
mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
sudo service mysql restart
from blogin.
你也可以新建用户,不一定要使用mysql的root用户,可以看这篇文章https://2dogz.cn/blog/article/30/
from blogin.
@weijiang1994 OK 谢谢 我好好看看。 你有时间可以把你做博客网站的记录一步步写下来。
from blogin.
你好 为啥老是出现下面错误 我感觉需要修改数据库连接的参数,我想问一下 哪里设置
sqlalchemy.exc.TimeoutError
sqlalchemy.exc.TimeoutError: QueuePool limit of size 10 overflow 10 reached, connection timed out, timeout 30 (Background on this error at: http://sqlalche.me/e/13/3o7r)
from blogin.
你好 为啥老是出现下面错误 我感觉需要修改数据库连接的参数,我想问一下 哪里设置
sqlalchemy.exc.TimeoutError sqlalchemy.exc.TimeoutError: QueuePool limit of size 10 overflow 10 reached, connection timed out, timeout 30 (Background on this error at: http://sqlalche.me/e/13/3o7r)
这个不是很清楚,可以看看这个https://stackoverflow.com/questions/24956894/sql-alchemy-queuepool-limit-overflow
from blogin.
@weijiang1994 添加博客的时候的 点击submit时候,出现了错误。
File "/home/ubuntu/.local/lib/python3.6/site-packages/whoosh/index.py", line 421, in init
TOC.read(self.storage, self.indexname, schema=self._schema)
File "/home/ubuntu/.local/lib/python3.6/site-packages/whoosh/index.py", line 664, in read
segments = stream.read_pickle()
File "/home/ubuntu/.local/lib/python3.6/site-packages/whoosh/filedb/structfile.py", line 245, in read_pickle
return load_pickle(self.file)
ValueError: unsupported pickle protocol: 5
from blogin.
你自己google搜一下,我也不清楚什么原因
from blogin.
@weijiang1994 可能是python版本原因,python3.8支持5,而现在服务器的python版本是3.6. 我也不知道咋解决除了升级以外。你开发的python版本是啥?
from blogin.
我服务器端部署的也是3.5可以正常运行,开发环境3.6 3.8都可以正常运行
from blogin.
from blogin.
@weijiang1994 我local3.8可以啊 !难道上传文件时候把3.8环境文件上传进去了吗。
from blogin.
不清楚
from blogin.
@weijiang1994 你可知道程序里哪里可能产生pickle(self.file)pickle 格式,估计保存h5格式。其他创建类别以及上传图片都可以。估计哪里有python3.8运行时候保存的环境文件。
from blogin.
在models.py
中找到图中的代码段,将红圈中的装饰器注释掉
from blogin.
@weijiang1994 OK啦 只要删除掉
/whooshee/blog$ l里面的文件.seg 和.toc文件
MAIN_WRITELOCK MAIN_megxx9m909gsh1v1.seg _MAIN_16.toc
估计这两个文件在local生成的。
from blogin.
我在.gitignore
文件中添加了这个路劲,不会上传到github上去,除非你是把本地的文件直接通过ftp的方式推上去。
from blogin.
@weijiang1994 我scp上传上去的
from blogin.
Related Issues (20)
- UnboundLocalError: local variable 'results' referenced before assignment HOT 2
- 我打算开发一个活动栏目。 HOT 2
- 请问如何部署到服务器? HOT 3
- 其它操作系统 HOT 20
- jinja2.exceptions.TemplateNotFound: main/index.html HOT 16
- 博客继续阅读 按钮 HOT 4
- 部署到AWS ec2 ubuntu 上出现了问题
- blueprint/front/blog.py", line 404, in load_one return jsonify({'one': one.content}) AttributeError: 'NoneType' object has no attribute 'content'
- 相应文件缺失? HOT 1
- 请问怎么解决configparser.NoSectionError: No section: 'baidu' HOT 2
- 大佬,请问这是什么原因啊 HOT 8
- 个人博客云端部署问题 HOT 2
- AttributeError: 'Babel' object has no attribute 'localeselector' HOT 6
- 进首页显示404 HOT 13
- 请问FileNotFoundError: [Errno 2] No such file or directory: 'E:\\_Study_Record\\git_files\\m_blog/history/e29c91a7c65dfdd2b5bff4294f4a5138.txt'怎么解决啊 HOT 2
- 博客地址无法访问了 HOT 6
- 后台 博客编辑栏 操作按钮无法点击 HOT 10
- avatar文件路径的问题 HOT 1
- 初始化数据库命令失败 HOT 13
- 依赖的文件缺失 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blogin.