在Linux shell上输入*** Starting uWSGI 2.0.17.1 (32bit) on [Wed Nov 21 03:52:10 2018] ***
compiled with version: 6.3.0 20170516 on 21 November 2018 02:28:06
os: Linux-4.14.78-v7+ #1156 SMP Tue Oct 23 14:34:39 BST 2018
nodename: pulsar
machine: armv7l
clock source: unix
detected number of CPU cores: 4
current working directory: /var/log/uwsgi
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 5918
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)
uwsgi socket 0 bound to UNIX address /home/bryan/Development/www/lab_app/lab_app_uwsgi.sock fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516]
Set PythonHome to /home/bryan/Development/www/lab_app
ImportError: No module named site
时,将显示欢迎消息:
python
这些行是从哪里来的?是在编译或安装过程中确定的吗?
我在系统上有另一个[root@localhost ~]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
可执行文件版本和一组库,但是当我输入python
时,它也显示与上述相同的欢迎消息。
谢谢
更新:
我使用绝对路径启动另一个版本的python。刚刚发现欢迎消息的内容与sys.version和sys.platform相同。但是,如果我将其他版本的python复制到另一台Linux计算机B,并且仍然使用绝对路径来运行它。我得到
python
此欢迎消息与机器B的python相同。
答案 0 :(得分:1)
编辑:C版本源代码类似于: https://github.com/python/cpython/blob/7e4db2f253c555568d56177c2fd083bcf8f88d34/Modules/main.c#L705
if (!Py_QuietFlag && (Py_VerboseFlag ||
(command == NULL && filename == NULL &&
module == NULL && stdin_is_interactive))) {
fprintf(stderr, "Python %s on %s\n",
Py_GetVersion(), Py_GetPlatform());
if (!Py_NoSiteFlag)
fprintf(stderr, "%s\n", COPYRIGHT);
}
其中Py_GetVersion()
返回基于MACRO的版本
/* Version as a string */
#define PY_VERSION "3.7.0a0"
所以它是由编译时间决定的,您可能把PATH弄乱了吗?
旧答案,实际上只是一个python模块
https://github.com/python/cpython/blob/7e4db2f253c555568d56177c2fd083bcf8f88d34/Lib/code.py#L214
if banner is None:
self.write("Python %s on %s\n%s\n(%s)\n" %
(sys.version, sys.platform, cprt,
self.__class__.__name__))
elif banner:
self.write("%s\n" % str(banner))
不确定这是否能回答您的问题,但仍然很有趣。
答案 1 :(得分:0)
我终于找到了原因。第二个python
二进制文件在启动时加载.so文件,并按以下方式加载libpython:
libpython2.7.so.1.0 => /lib64/libpython2.7.so.1.0 (0x00007f087cf58000)
这与我的系统python
相同。将LD_LIBRARY_PATH
设置为第二个python
的lib目录后,我可以看到正确的欢迎消息。