Mac上安装python3 和pip3

首先我不是用brew安装python3的,是用下载的python3.7.2的源码然后自己编译的。

一开始我用brew安装的python3,pip总是报错“ImportError: cannot import name HTTPSHandle”反正就是ssl方面的问题。网上找了一圈,说是ssl要先安装,然后重新编译python。

 

我去官网下载的源码:https://www.python.org/downloads/source/

下载的tar.xz文件,然后自己解压。

 

要先用brew安装openssl和openssl-devel

命令: brew install openssl

            brew install openssl-devel

 

然后

进入到解压的python的目录下

./configure --enable-shared --enable-loadable-sqlite-extensions  --prefix=/usr/local/bin/python3 --with-openssl=/usr/bin/openssl

 


sudo make
sudo make install

 

-bash-3.2$ pip3 -V
pip 18.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
-bash-3.2$ python3
Python 3.7.2 (default, Jan 25 2019, 10:03:23) 
[Clang 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymysql
Traceback (most recent call last):
  File "", line 1, in 
ModuleNotFoundError: No module named 'pymysql'
>>> exit()
-bash-3.2$ pip3 install pymysql
Collecting pymysql
  Downloading https://files.pythonhosted.org/packages/ed/39/15045ae46f2a123019aa968dfcba0396c161c20f855f11dea6796bcaae95/PyMySQL-0.9.3-py2.py3-none-any.whl (47kB)
    100% |████████████████████████████████| 51kB 14kB/s 
Installing collected packages: pymysql
Successfully installed pymysql-0.9.3
-bash-3.2$ python3
Python 3.7.2 (default, Jan 25 2019, 10:03:23) 
[Clang 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymysql
>>> from xlwt import Workbook
Traceback (most recent call last):
  File "", line 1, in 
ModuleNotFoundError: No module named 'xlwt'
>>> exit()
-bash-3.2$ pip3 install xlwt
Collecting xlwt
  Downloading https://files.pythonhosted.org/packages/44/48/def306413b25c3d01753603b1a222a011b8621aed27cd7f89cbc27e6b0f4/xlwt-1.3.0-py2.py3-none-any.whl (99kB)
    100% |████████████████████████████████| 102kB 96kB/s 
Installing collected packages: xlwt
Successfully installed xlwt-1.3.0
-bash-3.2$ python3
Python 3.7.2 (default, Jan 25 2019, 10:03:23) 
[Clang 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from xlwt import Workbook
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()
-bash-3.2$ 

 

你可能感兴趣的:(python,linux)