python版本和包安装问题

python版本和包安装问题

我的 Linux 服务器上有不同的 python 版本,运行Centos7.

[xyz@innolx20122]$ python
python             python2.7          python3.6          python3.7          python3.7m-config
python2            python3            python3.6m         python3.7m

我只想使用 python3.7 版本,因此在我的.bashrc文件中创建了一个别名。

alias python=python3.7

我已经安装了 python 调用模块,我将进一步使用它。

pip install invoke

它安装在默认的 python 2.7 位置

[xyz@innolx20122 ~]$ pip install invoke
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 pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: invoke in ./.local/lib/python2.7/site-packages (1.4.1)

我在运行调用任务时遇到问题,因为 2.7 版本不支持 **kwargs 参数。我该如何解决这个问题?

更新

我又创建了一个别名

pip=pip3.7

[xyz@innolx20122 ~]$ pip --version
pip 10.0.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

现在,当我运行 pip install invoke 时,出现此问题。

[xyz@innolx20122 ~]$ pip install invoke
Collecting invoke
  Using cached https://files.pythonhosted.org/packages/2c/16/f00efa99ae9f255142a230ce6819c37ae9dd29a7144477c1161cc72d01ed/invoke-1.4.1-py3-none-any.whl
Installing collected packages: invoke
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python3.7/site-packages/invoke'
Consider using the `--user` option or check the permissions.

You are using pip version 10.0.1, however version 20.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

我尝试使用

pip install invoke --user

之后我可以看到软件包已安装在该位置

[xyz@innolx20122 ~]$ pip install invoke --user

Requirement already satisfied: invoke in ./.local/lib/python3.7/site-packages (1.4.1)
You are using pip version 10.0.1, however version 20.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[xyz@innolx20122 ~]$ cd ./.local/lib/python3.7/site-packages
[xyz@innolx20122 site-packages]$ ls
invoke  invoke-1.4.1.dist-info



[xyz@innolx20122 ~]$ cd /usr/local/lib/python3.7/site-packages/
[xyz@innolx20122 site-packages]$ ls
easy_install.py  pip  pip-10.0.1.dist-info  pkg_resources  __pycache__  README.txt  setuptools  setuptools-39.0.1.dist-info


[xyz@innolx20122 sd-test]$ inv --list
Trace

    back (most recent call last):
      File "/usr/bin/inv", line 8, in <module>
        sys.exit(program.run())
      File "/home/xyz/.local/lib/python2.7/site-packages/invoke/program.py", line 373, in run
        self.parse_collection()
      File "/home/xyz/.local/lib/python2.7/site-packages/invoke/program.py", line 465, in parse_collection
        self.load_collection()
      File "/home/xyz/.local/lib/python2.7/site-packages/invoke/program.py", line 696, in load_collection
        module, parent = loader.load(coll_name)
      File "/home/xyz/.local/lib/python2.7/site-packages/invoke/loader.py", line 76, in load
        module = imp.load_module(name, fd, path, desc)
      File "/home/xyz/developer-workspace/vikrant-xyz/sd-test/tasks/__init__.py", line 5, in <module>
        from .airflow import *
      File "/home/xyz/developer-workspace/vikrant-xyz/sd--test/tasks/airflow.py", line 57
        **airflow_vars,

答案1

你有几个选择:

  1. 为 pip3 创建另一个别名,指向为 python 3.7 安装的 pip
  2. 使用 pip3 在你的 homedir 中安装你自己的 pip 并使用它
  3. 创建指向要使用的 pip 的符号链接,将其放入 ~/.local/bin 中(并确保它位于 $PATH 中)

只需确保您完全以用户身份运行,并且不会覆盖包所拥有的内容。

相关内容