如何在CPython上安装networkx软件包

问题描述

我已经在本地计算机(macOS Catalina,v.10.15.4)上安装了cpython [1],以加快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,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,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,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,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复制到ssl not available):

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