Mac安装Python-3.10.13

前言

  • Python-3.10最后一个提供dmg安装包的版本是3.10.11, 其实直接安装可以省不少事

安装步骤

  • 见Python-3.10.13/README.rst
bash 复制代码
# 进入安装压缩包解压后的目录
cd /Users/tedczj/WorkPlace/Python SDK/Python-3.10/Python-3.10.13
sudo su
./configure --enable-optimizations #说是用到的包会用stable版本的,很合我的心意就加上了,正常直接 ./configure 也可以
make
make install #安装完成
  • 然后在Pycharm里创建虚拟环境报错了,看起来像是python依赖的ssl模块的问题
sql 复制代码
# Execute Command
/usr/local/bin/python3.10 /Applications/PyCharm.app/Contents/plugins/python/helpers/virtualenv-20.16.7.pyz /Users/tedczj/WorkPlace/mobot/mobot-exercise/v0.1/venv

# Error Occured
ModuleNotFoundError: No module named '_ssl'

# Command Output
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/virtualenv-20.16.7.pyz/__main__.py", line 167, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/virtualenv-20.16.7.pyz/__main__.py", line 161, in run
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/virtualenv-20.16.7.pyz/virtualenv/__init__.py", line 1, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/virtualenv-20.16.7.pyz/virtualenv/run/__init__.py", line 9, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/virtualenv-20.16.7.pyz/virtualenv/seed/wheels/__init__.py", line 1, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/virtualenv-20.16.7.pyz/virtualenv/seed/wheels/acquire.py", line 9, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/virtualenv-20.16.7.pyz/virtualenv/seed/wheels/bundle.py", line 2, in <module>
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/virtualenv-20.16.7.pyz/virtualenv/seed/wheels/periodic_update.py", line 9, in <module>
  File "/usr/local/lib/python3.10/ssl.py", line 99, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
  • 查了一下解决大概分2步:
    1. 本机安装openssl
    2. python安装的配置文件需要调整
bash 复制代码
brew install openssl@3
Warning: openssl@3 3.1.2 is already installed and up-to-date.

which openssl
/opt/homebrew/bin/openssl

-l /opt/homebrew/bin/openssl
lrwxr-xr-x@ 1 tedczj  admin  37 Sep  2 23:21 /opt/homebrew/bin/openssl -> ../Cellar/openssl@3/3.1.2/bin/openssl
  • 注意这里用了个相对路径,实际位置要到你的homebrew根目录去找Cellar文件夹的位置,我这里的绝对路径是
bash 复制代码
/opt/homebrew/Cellar/openssl@3/3.1.2/bin/openssl

ls
AUTHORS.md		NEWS.md			lib #注意这个文件夹名是lib 还是lib64
CHANGES.md		README.md		share
INSTALL_RECEIPT.json	bin
LICENSE.txt		include
  • 重新解压python安装压缩包
  • 修改Python-3.10.13/Modules/Setup
ruby 复制代码
# Socket module helper for socket(2)

_socket socketmodule.c # 放开注释

  

# Socket module helper for SSL support; you must comment out the other

# socket line above, and edit the OPENSSL variable:

OPENSSL=/opt/homebrew/Cellar/openssl@3/3.1.2 # 替换成本机openssl安装目录

_ssl _ssl.c \ # 放开注释

-I$(OPENSSL)/include -L$(OPENSSL)/lib \ # 放开注释 上面的目录是lib这里就是lib, 上面如果是lib64这里就是lib64

-lssl -lcrypto # 放开注释

#_hashlib _hashopenssl.c \

# -I$(OPENSSL)/include -L$(OPENSSL)/lib \

# -lcrypto
  • 重新执行安装流程
相关推荐
蒙娜丽宁7 分钟前
《Python OpenCV从菜鸟到高手》——零基础进阶,开启图像处理与计算机视觉的大门!
python·opencv·计算机视觉
光芒再现dev9 分钟前
已解决,部署GPTSoVITS报错‘AsyncRequest‘ object has no attribute ‘_json_response_data‘
运维·python·gpt·语言模型·自然语言处理
好喜欢吃红柚子22 分钟前
万字长文解读空间、通道注意力机制机制和超详细代码逐行分析(SE,CBAM,SGE,CA,ECA,TA)
人工智能·pytorch·python·计算机视觉·cnn
小馒头学python27 分钟前
机器学习是什么?AIGC又是什么?机器学习与AIGC未来科技的双引擎
人工智能·python·机器学习
神奇夜光杯36 分钟前
Python酷库之旅-第三方库Pandas(202)
开发语言·人工智能·python·excel·pandas·标准库及第三方库·学习与成长
千天夜1 小时前
使用UDP协议传输视频流!(分片、缓存)
python·网络协议·udp·视频流
测试界的酸菜鱼1 小时前
Python 大数据展示屏实例
大数据·开发语言·python
羊小猪~~1 小时前
神经网络基础--什么是正向传播??什么是方向传播??
人工智能·pytorch·python·深度学习·神经网络·算法·机器学习
假装我不帅1 小时前
asp.net framework从webform开始创建mvc项目
后端·asp.net·mvc