如何在 CPython 上安装 networkx 包

how to install networkx package on CPython

我在我的本地机器上安装了 CPython [1] (macOS Catalina, v. 10.15.4) 来加速 networkx 包中函数 optimize_graph_edit_distance 的计算。之前,我在 运行 宁 Python3 上的代码,这需要很多时间。但是,当我 运行 使用 CPython 的代码时(CPython 的别名是 python3),我得到以下错误:

Traceback (most recent call last):
  File "/Users/olha/Desktop/GED_optima.py", line 3, in <module>
    import networkx as nx
ModuleNotFoundError: No module named 'networkx'

我尝试了 python3 -m pip3 install networkx,但出现以下错误:

Defaulting to user installation because normal site-packages is not writeable
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/networkx/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/networkx/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/networkx/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/networkx/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/networkx/
Could not fetch URL https://pypi.org/simple/networkx/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/networkx/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement networkx (from versions: none)
ERROR: No matching distribution found for networkx
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

有人知道如何在 CPython 上安装 networkx 吗?

谢谢!

奥尔哈 [1]: https://github.com/python/cpython#documentation

您可以通过以下方式安装 networkx:

git clone https://github.com/networkx/networkx.git
cd networkx
sudo python setup.py install

尝试运行以下命令(从Mayur Deshmukh's answer to ssl not available复制):

python3 -m pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org --upgrade pip