升级到 Python 3.5 但 uWSGI 使用 Python 2.7
Upgrading to Python 3.5 but uWSGI using Python 2.7
我目前正在尝试将我们的 Python 2.7 项目升级到 3.5。我正在使用 pipenv 创建一个虚拟环境来执行此操作。我们的服务器已升级到 Ubuntu 16.04。在我当前的 pip 环境中,当 运行 python -V
它正确 returns “Python 3.5.2”。但是,当尝试启动 uWSGI 时,我收到以下错误:
Traceback (most recent call last):
File "/usr/local/bin/pipenv", line 7, in <module>
from pipenv import cli
ImportError: No module named 'pipenv'
[uWSGI] getting INI configuration from /opt/site/uwsgi.ini
*** Starting uWSGI 2.0.15 (64bit) on [Tue Jul 21 19:47:23 2020] ***
compiled with version: 4.8.4 on 05 October 2017 19:12:33
os: Linux-4.4.0-185-generic #215-Ubuntu SMP Mon Jun 8 21:53:19 UTC 2020
nodename: ip-172-31-15-50
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /opt/site/mysite
detected binary path: /usr/local/bin/uwsgi
chdir() to /opt/site/mysite
your processes number limit is 64022
your memory page size is 4096 bytes
*** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
Python version: 2.7.16 (default, Mar 26 2019, 10:00:46) [GCC 4.8.4]
Set PythonHome to /home/u_admin/.local/share/virtualenvs/site-qq5I0OuW
ImportError: No module named site
我认为问题与此行有关:
Python version: 2.7.16 (default, Mar 26 2019, 10:00:46) [GCC 4.8.4]
尽管我不确定为什么 uWSGI 仍在使用 Python 2.
如有任何帮助,我们将不胜感激。谢谢!
编辑:
这是我的 uwsgi.ini:
[uwsgi]
# Django-related settings
# the base directory (full path)
# main Django wsgi file
chdir = /opt/my_project/portal
module = wsgi.portal:application
# Exit with error code if app can't be imported
need-app = true
# process-related settings
# graceful reload
stopsignal = SIGHUP
# Exit when supervisord sends SIGTERM instead of restarting
die-on-term = true
# master
master = true
# maximum number of worker processes
processes = 5
threads = 3
max-requests = 3000
# Give up if a request takes so long that nginx has already timed out
harakiri = 35
# for NewRelic
enable-threads = true
single-interpreter = true
# the socket (use the full path to be safe)
socket = /tmp/uwsgi.sock
stats = /tmp/uwsgi_stats.sock
chown-socket = myproject:myprojecttech
chmod-socket = 664
# At exit, preserve socket for use on the next launch
vacuum = false
plugins-dir = /usr/lib/uwsgi/plugins
plugins = python35
home = /home/u_admin/.local/share/virtualenvs/agportal-qq5I0OuW
编辑:
在 运行 uwsgi -H path/to/python
之后,我收到以下消息:
*** Starting uWSGI 2.0.19.1 (64bit) on [Fri Jul 24 19:14:30 2020] ***
compiled with version: 5.4.0 20160609 on 20 July 2020 17:01:06
os: Linux-4.4.0-185-generic #215-Ubuntu SMP Mon Jun 8 21:53:19 UTC 2020
nodename: ip-172-31-15-50
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /opt/spensa/site
detected binary path: /home/u_admin/.local/share/virtualenvs/site-qq5I0OuW/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 64022
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
The -s/--socket option is missing and stdin is not a socket.
这并没有改变问题的状态。
如果您使用默认 venv
或 virtualenv 来创建您将要使用的虚拟环境。然后你可以像下面这样指定路径:
uwsgi -H /fullpath/to/virtualenv
这里-H
是快捷方式。关于此的文档:uWSGI Options.
我在“conf.d”文件夹中找到了我们supervisord结构下的一个文件。 (/etc/supervisor/confd
).
此文件使用名为 vuwsgi.py 的文件启动 uwsgi(我猜理论上是虚拟 uwsgi)。
更改此行后:
os.execvp('uwsgi', ['uwsgi', '-H', venv_path] + sys.argv[1:])
到
os.execvp('path/to/my/virtualenv/bin/uwsgi', ['path/to/my/virtualenv/bin/uwsgi', '-H', venv_path] + sys.argv[1:])
uWSGI 从使用 Python 2.7 更改为 Python 3.5。
我目前正在尝试将我们的 Python 2.7 项目升级到 3.5。我正在使用 pipenv 创建一个虚拟环境来执行此操作。我们的服务器已升级到 Ubuntu 16.04。在我当前的 pip 环境中,当 运行 python -V
它正确 returns “Python 3.5.2”。但是,当尝试启动 uWSGI 时,我收到以下错误:
Traceback (most recent call last):
File "/usr/local/bin/pipenv", line 7, in <module>
from pipenv import cli
ImportError: No module named 'pipenv'
[uWSGI] getting INI configuration from /opt/site/uwsgi.ini
*** Starting uWSGI 2.0.15 (64bit) on [Tue Jul 21 19:47:23 2020] ***
compiled with version: 4.8.4 on 05 October 2017 19:12:33
os: Linux-4.4.0-185-generic #215-Ubuntu SMP Mon Jun 8 21:53:19 UTC 2020
nodename: ip-172-31-15-50
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /opt/site/mysite
detected binary path: /usr/local/bin/uwsgi
chdir() to /opt/site/mysite
your processes number limit is 64022
your memory page size is 4096 bytes
*** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3
Python version: 2.7.16 (default, Mar 26 2019, 10:00:46) [GCC 4.8.4]
Set PythonHome to /home/u_admin/.local/share/virtualenvs/site-qq5I0OuW
ImportError: No module named site
我认为问题与此行有关:
Python version: 2.7.16 (default, Mar 26 2019, 10:00:46) [GCC 4.8.4]
尽管我不确定为什么 uWSGI 仍在使用 Python 2.
如有任何帮助,我们将不胜感激。谢谢!
编辑:
这是我的 uwsgi.ini:
[uwsgi]
# Django-related settings
# the base directory (full path)
# main Django wsgi file
chdir = /opt/my_project/portal
module = wsgi.portal:application
# Exit with error code if app can't be imported
need-app = true
# process-related settings
# graceful reload
stopsignal = SIGHUP
# Exit when supervisord sends SIGTERM instead of restarting
die-on-term = true
# master
master = true
# maximum number of worker processes
processes = 5
threads = 3
max-requests = 3000
# Give up if a request takes so long that nginx has already timed out
harakiri = 35
# for NewRelic
enable-threads = true
single-interpreter = true
# the socket (use the full path to be safe)
socket = /tmp/uwsgi.sock
stats = /tmp/uwsgi_stats.sock
chown-socket = myproject:myprojecttech
chmod-socket = 664
# At exit, preserve socket for use on the next launch
vacuum = false
plugins-dir = /usr/lib/uwsgi/plugins
plugins = python35
home = /home/u_admin/.local/share/virtualenvs/agportal-qq5I0OuW
编辑:
在 运行 uwsgi -H path/to/python
之后,我收到以下消息:
*** Starting uWSGI 2.0.19.1 (64bit) on [Fri Jul 24 19:14:30 2020] ***
compiled with version: 5.4.0 20160609 on 20 July 2020 17:01:06
os: Linux-4.4.0-185-generic #215-Ubuntu SMP Mon Jun 8 21:53:19 UTC 2020
nodename: ip-172-31-15-50
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /opt/spensa/site
detected binary path: /home/u_admin/.local/share/virtualenvs/site-qq5I0OuW/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 64022
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
The -s/--socket option is missing and stdin is not a socket.
这并没有改变问题的状态。
如果您使用默认 venv
或 virtualenv 来创建您将要使用的虚拟环境。然后你可以像下面这样指定路径:
uwsgi -H /fullpath/to/virtualenv
这里-H
是快捷方式。关于此的文档:uWSGI Options.
我在“conf.d”文件夹中找到了我们supervisord结构下的一个文件。 (/etc/supervisor/confd
).
此文件使用名为 vuwsgi.py 的文件启动 uwsgi(我猜理论上是虚拟 uwsgi)。
更改此行后:
os.execvp('uwsgi', ['uwsgi', '-H', venv_path] + sys.argv[1:])
到
os.execvp('path/to/my/virtualenv/bin/uwsgi', ['path/to/my/virtualenv/bin/uwsgi', '-H', venv_path] + sys.argv[1:])
uWSGI 从使用 Python 2.7 更改为 Python 3.5。