在 python 2.7 上安装 python 3.7.3 时出现 Python 命令未找到错误

在 python 2.7 上安装 python 3.7.3 时出现 Python 命令未找到错误

我有 Python 2,位于

# which python
/bin/python

# python --version
Python 2.7.5

我正在使用以下文章安装 python 3.7https://wiki.centos-webpanel.com/install-django

安装python后

# cd /usr/local/src
# wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
# tar xvf Python-3.7.3.tgz
# cd Python-3.7.3
# ./configure --with-ensurepip=install --enable-shared
# make
# make install
# ln -s /usr/local/lib/libpython3.7m.so.1.0 /usr/lib64/libpython3.7m.so.1.0

当我使用以下命令升级 pip 时,它给出命令未找到

# pip3.7 install --upgrade pip
bash: pip3.7: command not found

我试过

# python3.7 pip install --upgrade pip
bash: python3.7: command not found

注意:请注意,安装后,新的 python 二进制路径将位于 /usr/local/bin/python

编辑1:我使用以下命令创建了符号链接

[root@host Python-3.7.3]# ln -s /usr/local/lib/libpython3.7m.so.1.0 /usr/lib64/libpython3.7m.so.1.0
[root@host Python-3.7.3]# cd /usr/local/lib/
[root@host lib]# ll
total 13380
lrwxrwxrwx.  1 root root       20 Jul  7 11:09 libpython3.7m.so -> libpython3.7m.so.1.0
-r-xr-xr-x.  1 root root 13678000 Jul  7 11:09 libpython3.7m.so.1.0
-r-xr-xr-x.  1 root root     7680 Jul  7 11:09 libpython3.so
drwxr-xr-x. 15 root root      288 Jun 23 07:11 php
drwxr-xr-x.  2 root root       67 Jul  7 11:09 pkgconfig
drwxr-xr-x. 35 root root     8192 Jul  7 11:09 python3.7

编辑2:从 python3.7 文件夹运行命令后出现以下错误

[root@host python3.7]# python3.7 -m pip install --upgrade pip
bash: python3.7: command not found
[root@host python3.7]# pwd
/usr/local/lib/python3.7

编辑3:

[root@host python3.7]# python -m pip install -upgrade pip
Could not import runpy module
[root@host python3.7]# python3 -m pip install -upgrade pip
bash: python3: command not found

编辑4:

[root@host python3.7]# which python3
/usr/bin/which: no python3 in (/sbin:/bin:/usr/sbin:/usr/bin)

编辑5:

[root@host usr]# cd /usr/local/bin
[root@host bin]# ll
total 23580
lrwxrwxrwx. 1 root root        8 Jul  7 11:09 2to3 -> 2to3-3.7
-rwxr-xr-x. 1 root root      101 Jul  7 11:09 2to3-3.7
-rwxr-xr-x. 1 root root      241 Jul  2 19:24 easy_install-3.7
lrwxrwxrwx. 1 root root        7 Jul  7 11:09 idle3 -> idle3.7
-rwxr-xr-x. 1 root root       99 Jul  7 11:09 idle3.7
-rwxr-xr-x. 1 root root      817 Jul 20  2018 pear
-rwxr-xr-x. 1 root root      838 Jul 20  2018 peardev
-rwxr-xr-x. 1 root root      754 Jul 20  2018 pecl
lrwxrwxrwx. 1 root root        9 Jun 23 07:11 phar -> phar.phar
-rwxr-xr-x. 1 root root    14829 Jul 20  2018 phar.phar
-rwxr-xr-x. 1 root root 12036016 Jul 20  2018 php
-rwxr-xr-x. 1 root root 12009264 Jul 20  2018 php-cgi
-rwxr-xr-x. 1 root root     3232 Jul 20  2018 php-config
-rwxr-xr-x. 1 root root     4526 Jul 20  2018 phpize
-rwxr-xr-x. 1 root root      223 Jul  2 19:24 pip3
-rwxr-xr-x. 1 root root      223 Jul  2 19:24 pip3.7
lrwxrwxrwx. 1 root root        8 Jul  7 11:09 pydoc3 -> pydoc3.7
-rwxr-xr-x. 1 root root       84 Jul  7 11:09 pydoc3.7
lrwxrwxrwx. 1 root root        9 Jul  7 11:09 python3 -> python3.7
-rwxr-xr-x. 2 root root    11200 Jul  7 11:09 python3.7
lrwxrwxrwx. 1 root root       17 Jul  7 11:09 python3.7-config -> python3.7m-config
-rwxr-xr-x. 2 root root    11200 Jul  7 11:09 python3.7m
-rwxr-xr-x. 1 root root     3097 Jul  7 11:09 python3.7m-config
lrwxrwxrwx. 1 root root       16 Jul  7 11:09 python3-config -> python3.7-config
lrwxrwxrwx. 1 root root       10 Jul  7 11:09 pyvenv -> pyvenv-3.7
-rwxr-xr-x. 1 root root      441 Jul  7 11:09 pyvenv-3.7

编辑6:

# python -m pip install --upgrade pip
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages (20.1.1)

答案1

Python 3.7 可执行文件的安装目录/usr/local/bin不在您的PATH.您可以PATH在运行返回的错误中看到您的错误which python3,该错误打印/sbin:/bin:/usr/sbin:/usr/binPATH.您还可以通过将变量的内容打印到终端来查看路径是什么,例如echo $PATH

您可以/usr/local/bin通过运行以下命令临时添加到您的路径:

export PATH="$PATH:/usr/local/bin"

这会将$PATH变量设置为其自身的当前内容,但附加/usr/local/bin了内容。 shell 中的条目PATH由冒号 ( ) 分隔:

要永久设置PATH为包含,/usr/local/bin您必须修改 shell 的登录配置文件,以最常见的 shell 为例,bash 将.bash_profile在您的主目录中有一个名为的文件,或者.profile如果.bash_profile不存在的话。在该文件的底部,您可以添加上述命令以在每次登录时导出路径,确保您在登录后能够立即轻松地访问 Python 3.7。

相关内容