python - 升级到 Python 3.5 但 uWSGI 使用 Python 2.7
问题描述
我目前正在尝试将我们的 Python 2.7 项目升级到 3.5。我正在使用 pipenv 创建一个虚拟环境来执行此操作。我们的服务器已升级到 Ubuntu 16.04。在我当前的 pip 环境中,python -V
正确运行时会返回“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.
这并没有改变问题的状态。
解决方案
如果您使用 defaultvenv
或virtualenv 来创建您将要使用的虚拟环境。然后您可以指定路径,如下所示:
uwsgi -H /fullpath/to/virtualenv
这-H
是捷径。相关文档:uWSGI 选项。
推荐阅读
- java - 在接口 VS 中定义的匿名类。接口外的具体类
- python - 如何在列中仅放置部分字符串值?
- excel - Excel VBA,比较两个不同列中的值并保留整行以获得共同值
- javascript - 尝试使用 getElementById 更改 innerHTML 时,ng-repeat 不起作用
- arduino - 错误:没有匹配函数调用 'UdpContext::listen(const ip_addr_t&, int&)' if(!_udp_ota->listen(*IP_ADDR_ANY, _port))
- angular - 创建新 Angular 项目后的多个 karma.conf.js 文件
- c++ - 如何计算OpenCV中每个圆圈中的像素数?
- excel - 以只读访问权限写入数据库 [TSQL 存储过程]
- http - HTTP 的登录方法
- javascript - How do I get these two elements to align side by side?