在以前的文章中,我在centos服務器裝了python3而且給python與pip創建了軟鏈,利用git上傳代碼到centos服務器以後利用終端運行app.py的時候會報錯。html
[root@izm5e0qcppq4b6rgy4d5vfz flaskServer]# python app.py Traceback (most recent call last): File "app.py", line 2, in <module> from flask import Flask File "/usr/local/python3/lib/python3.7/site-packages/flask/__init__.py", line 21, in <module> from .app import Flask, Request, Response File "/usr/local/python3/lib/python3.7/site-packages/flask/app.py", line 25, in <module> from . import cli, json File "/usr/local/python3/lib/python3.7/site-packages/flask/cli.py", line 18, in <module> import ssl File "/usr/local/python3/lib/python3.7/ssl.py", line 98, in <module> import _ssl # if we can't import it, let the error propagate ModuleNotFoundError: No module named '_ssl' [root@izm5e0qcppq4b6rgy4d5vfz flaskServer]# python3 app.py Traceback (most recent call last): File "app.py", line 2, in <module> from flask import Flask ModuleNotFoundError: No module named 'flask'
1. 自定義安裝了python3的位置,而且創建了軟鏈,
python
項目中引入flask的時候提示報錯,而且運行中執行不一樣的python命令提示報錯還不同:
git
安裝flask環境之後仍是不行,shell
猜測應該是裝python3 而且創建軟鏈的過程當中,哪一個地方弄錯了。一時不知道該怎麼辦。想起來 flask文檔 有這麼一句段:json
因而想到用 virtualenv 創建一個虛擬環境,安裝flask,再運行
代碼:flask
[root]# sudo pip install virtualenv [root]# virtualenv venv New python executable in /var/www/flaskServer/venv/bin/python2 Also creating executable in /var/www/flaskServer/venv/bin/python Please make sure you remove any previous custom paths from your /root/.pydistutils.cfg file. Installing setuptools, pip, wheel...done. [rootr]# chmod 755 venv/bin/activate [rootr]# venv/bin/activate [rootr]# pip3 install Flask ... [rootr]# pip3 install requests ... [rootr]# python3 app.py * Serving Flask app "app" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. * Debug mode: off * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
重啓服務器以後,利用python3執行命令,照樣能夠運行,不知道爲何可是就是這麼解決了。。。centos
應該是和系統自帶的python2.7有關,而我給項目建立了一個虛擬環境,應該我是隔絕了python3對python2.7模塊的引用,以後python3找不到對應的模塊,從新安裝,pip3從新建立新的路徑,python3可以找到對應的模塊。可以運行。服務器