Mac10.14编译源码安装python3.7.9(同时解决openssl的问题),基于此版本的python的virtualenv创建多个版本的python虚拟环境

//

 

1.安装homebrew:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

 

2.安装openssl

brew install openssl

提示信息:

==> Downloading https://homebrew.bintray.com/bottles/openssl%401.1-1.1.1h.mojave.bottle.tar.gz

==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/d4ef27b41d0596d20b79a43a43554d4ea1395f0ef9affdcf0ce74114a00e2572?r

######################################################################## 100.0%

==> Pouring [email protected]

==> Caveats

A CA file has been bootstrapped using certificates from the system

keychain. To add additional certificates, place .pem files in

/usr/local/etc/[email protected]/certs

 

and run

/usr/local/opt/[email protected]/bin/c_rehash

 

[email protected] is keg-only, which means it was not symlinked into /usr/local,

because macOS provides LibreSSL.

 

If you need to have [email protected] first in your PATH run:

echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> /Users/wangpeng/.bash_profile

 

For compilers to find [email protected] you may need to set:

export LDFLAGS="-L/usr/local/opt/[email protected]/lib"

export CPPFLAGS="-I/usr/local/opt/[email protected]/include"

 

==> Summary

/usr/local/Cellar/[email protected]/1.1.1h: 8,067 files, 18.4MB

 

 

# 查看安装完成的信息

brew list openssl

 

 

3.安装系统某些文件

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Password:

installer: Package name is macOS_SDK_headers_for_macOS_10.14

installer: Installing at base path /

installer: The install was successful.

 

 

4.官网下载源码包进行安装:

https://www.python.org

Python-3.7.9.tgz

解压

进入源码文件并安装

cd path/to/Python-3.7.9

 

./configure --prefix=/usr/local/Cellar/python/3.7.9 --with-openssl=/usr/local/opt/openssl

 

make clean

make -j6

 

The necessary bits to build these optional modules were not found:

_gdbm ossaudiodev spwd

To find the necessary bits, look in setup.py in detect_modules() for the module's name.

 

 

The following modules found by detect_modules() in setup.py, have been

built by the Makefile instead, as configured by the Setup files:

_abc atexit pwd

time

 

 

Failed to build these modules:

_lzma

 

#提示有部分模块报错,以后有时间再解决吧

 

#最后

make install

 

成功安装到/usr/local/Cellar/python/3.7.9

 

/usr/local/Cellar/python/3.7.9/bin/python3.7

import ssl

没有报错

 

/**

配置到当前用户环境变量

sudo vim ~/.bash_profile

添加这句

export PATH=/usr/local/Cellar/python/3.7.9/bin:$PATH

然后

source ~/.bash_profile

 

python3.7

pip3

可以正常使用了

*/

 

5.安装virtualenv

ll /usr/local/Cellar/python/3.7.9/lib/python3.7/site-packages/

/usr/local/Cellar/python/3.7.9/bin/pip3 install virtualenv

ll /usr/local/Cellar/python/3.7.9/lib/python3.7/site-packages/           #多了一些包

/usr/local/Cellar/python/3.7.9/bin/virtualenv --version

 

6.创建多个python3.7的虚拟环境(根据具体业务应用创建去吧)

/usr/local/Cellar/python/3.7.9/bin/virtualenv -p /usr/local/Cellar/python/3.7.9/bin/python3.7 ./item_recommend_py379
/usr/local/Cellar/python/3.7.9/bin/virtualenv -p /usr/local/Cellar/python/3.7.9/bin/python3.7 ./tensorfow21_py379

  等等等

  激活环境 source item_recommend_py379/bin/activate

  退出环境 deactivate

  激活环境 source ./tensorfow21_py379/bin/activate

   pip install pandas

  退出环境 deactivate

 

7.官网下载python3.6.12源码进行安装

  tar -zxvf Python-3.6.12.tgz

  cd ./Python-3.6.12

  修改 setup.py

  将文件中所有出现 /usr/local/ssl 的路径,改为 /usr/local/Cellar/[email protected]/1.1.1h。(应该有两处)

  注意:这个路径是我的 openssl 安装路径,根据电脑不同可能有所变化。

  修改 modules/setup.dist

  搜索 #SSL=,可以找到如下这4行代码(下面是我修改完毕的样子)

  • 取消注释
    • 将他们前面的#号删除掉
  • 修改路径
    • SSL=你的openssl 安装路径
SSL=/usr/local/Cellar/[email protected]/1.1.1h
_ssl _ssl.c \
    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    -L$(SSL)/lib -lssl -lcrypto

  ./configure --prefix=/usr/local/Cellar/python/3.6.12

  make clean

  make -j6

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_gdbm                 ossaudiodev           spwd
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_ssl                  atexit                pwd
time

Failed to build these modules:
_lzma

#提示有部分模块报错,以后有时间再解决吧

 

make install

成功安装到/usr/local/Cellar/python/3.6.12

/usr/local/Cellar/python/3.6.12/bin/python3.6

import ssl

没有报错,python3.6.12也安装成功了

 

8.创建多个python3.6的虚拟环境(根据具体业务应用创建去吧)

/usr/local/Cellar/python/3.7.9/bin/virtualenv -p /usr/local/Cellar/python/3.6.12/bin/python3.6 ./tensorfow21_py3612

  等等等

  激活环境 source ./tensorfow21_py3612/bin/activate

   pip install numpy

  退出环境 deactivate

 

9.类似的,通过上面方法还可以安装创建python3.5的多个虚拟环境

 

The end

 

 

//

 

 

 

 

 

 

 

你可能感兴趣的:(编程语言,深度学习,机器学习,python,mac,openssl)