問題背景
root 使用者可以執行pip install mkdocs
但gitlab-runner 執行pip install mkdocs 則下列錯誤
pip install mkdocs
Traceback (most recent call last):
File "/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named `pip._internal`
經過排查,發現是gitlab-runner 在某些python path 的許可權問題
解決方法
1. cat /bin/pip 檢視使用的python 程式碼
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal import main
if __name__ == `__main__`:
sys.argv[0] = re.sub(r`(-script.pyw?|.exe)?$`, ``, sys.argv[0])
sys.exit(main())
可知,使用的是python3
檢視path 路徑
切換到root 使用者
然後在命令列執行:
[root@test75vm1 ~]# python3
Python 3.4.5 (default, May 29 2017, 15:17:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
[``, `/usr/lib64/python34.zip`, `/usr/lib64/python3.4`, `/usr/lib64/python3.4/plat-linux`, `/usr/lib64/python3.4/lib-dynload`, `/usr/lib64/python3.4/site-packages`, `/usr/lib/python3.4/site-packages`]
check path 路徑的許可權
ls -rlt /usr/lib/python3.4/site-packages
修改python path 路徑的許可權
ls -rlt 發現有寫目錄是沒有執行許可權的。
執行命令
chmod 755 -R /usr/lib64/python3.4 /usr/lib64/python3.4/plat-linux /usr/lib64/python3.4/lib-dynload /usr/lib64/python3.4/site-packages /usr/lib/python3.4/site-packages