Linux

python版本和包安裝問題

  • September 19, 2020

我在執行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 呼叫 –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. 為 pip3 創建另一個別名,指向為 python 3.7 安裝的 pip
  2. 使用 pip3 在你的 homedir 中安裝你自己的 pip 並使用它來代替
  3. 創建指向要使用的 pip 的符號連結,將其放入 ~/.local/bin(並確保它位於 $PATH 中)

只需確保您完全以使用者身份執行,而不是覆蓋包所擁有的內容。

引用自:https://unix.stackexchange.com/questions/610156