Python2: 安装 networkx

Python2: installing networkx

我正在尝试在 python 2.7.18 上安装 networkx:

pip2 install networkx

我收到以下错误:

Running setup.py install for networkx ... error
    ERROR: Command errored out with exit status 1:
     command: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/1b/8lq89lxj07bd6rvtl1k6g1b80000gn/T/pip-install-xAglEZ/networkx/setup.py'"'"'; _file='"'"'/private/var/folders/1b/8lq89lxj07bd6rvtl1k6g1b80000gn/T/pip-install-xAglEZ/networkx/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file_, '"'"'exec'"'"'))' install --record /private/var/folders/1b/8lq89lxj07bd6rvtl1k6g1b80000gn/T/pip-record-cJQmE6/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/networkx
         cwd: /private/var/folders/1b/8lq89lxj07bd6rvtl1k6g1b80000gn/T/pip-install-xAglEZ/networkx/

最后:

error: could not create '/Library/Frameworks/Python.framework/Versions/2.7/share/doc/networkx-2.2': Permission denied
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/1b/8lq89lxj07bd6rvtl1k6g1b80000gn/T/pip-install-xAglEZ/networkx/setup.py'"'"'; _file='"'"'/private/var/folders/1b/8lq89lxj07bd6rvtl1k6g1b80000gn/T/pip-install-xAglEZ/networkx/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file_, '"'"'exec'"'"'))' install --record /private/var/folders/1b/8lq89lxj07bd6rvtl1k6g1b80000gn/T/pip-record-cJQmE6/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/networkx Check the logs for full command output.

我该怎么办?

这意味着您没有足够的权限。


您可以 运行 使用 sudo 命令(如果您是 root 用户):

sudo pip2 install networkx

或者只为当前用户安装它

pip2 install networkx --user

PS:考虑升级到pip3