Win10+VS2015+python3.6.8源码编译安装

参考:VS2015编译python 3.6.4源码

参考:解决python “No module named pip”的方法

 

(1)修改build.bat

set platf=x64
set conf=Release

首先编译Release版本,Debug版本在使用pip安装依赖包时会报错。Debug版本可以在最后编译。

 

(2)执行build.bat会在根目录下生成externals文件夹,并用Nuget下载相关的依赖包,但是通常有的依赖包无法完整下载(此后不需要再运行build.bat,其作用是下载依赖包并编译python源码,现在我们手动下载依赖,用VS2015编译),需要手动下载。在get_externals.bat中得知下载网址和依赖包及其版本。VS2015打开项目,根据项目属性中的“包含目录”信息,把下载后的文件放在相应位置。

Win10+VS2015+python3.6.8源码编译安装_第1张图片

if "%ORG%"=="" (set ORG=python)

call "%PCBUILD%\find_python.bat" "%PYTHON%"

if "%PYTHON%"=="" (
    where /Q git || echo Python 3.6 could not be found or installed, and git.exe is not on your PATH && exit /B 1
)

echo.Fetching external libraries...

set libraries=
set libraries=%libraries%                                    bzip2-1.0.6
if NOT "%IncludeSSL%"=="false" set libraries=%libraries%     openssl-1.0.2q
set libraries=%libraries%                                    sqlite-3.21.0.0
if NOT "%IncludeTkinter%"=="false" set libraries=%libraries% tcl-core-8.6.6.0
if NOT "%IncludeTkinter%"=="false" set libraries=%libraries% tk-8.6.6.0
if NOT "%IncludeTkinter%"=="false" set libraries=%libraries% tix-8.4.3.6
set libraries=%libraries%                                    xz-5.2.2

for %%e in (%libraries%) do (
    if exist "%EXTERNALS_DIR%\%%e" (
        echo.%%e already exists, skipping.
    ) else if "%PYTHON%"=="" (
        echo.Fetching %%e with git...
        git clone --depth 1 https://github.com/%ORG%/cpython-source-deps --branch %%e "%EXTERNALS_DIR%\%%e"
    ) else (
        echo.Fetching %%e...
        %PYTHON% -E "%PCBUILD%\get_external.py" -O %ORG% -e "%EXTERNALS_DIR%" %%e
    )
)

 

(3)运行python

WIN+R打开命名窗口,cd到python.exe所在目录

C:\Users\zlf>cd C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>python
Python 3.6.8 (default, Jun 11 2019, 12:22:02) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>

(4)安装pip

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>python -m pip install
C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64\python.exe: No module named pip

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>python -m ensurepip
Looking in links: C:\Users\zlf\AppData\Local\Temp\tmpqemdmz26
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>

Win10+VS2015+python3.6.8源码编译安装_第2张图片

(5)添加环境变量PATH

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\Scripts

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8

 

(6)重命名

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>pip3
Fatal error in launcher: Unable to create process using '"c:\caffe_draft\thirdparty\python-3.6.8\python-3.6.8\pcbuild\amd64\python36.exe"  "C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\Scripts\pip3.exe" '

python.exe 复制一份,重命名为python36.exe

pip.exe不用改,因为已经存在pip3.exe

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>pip3

Usage:
  pip3  [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
  --log                 Path to a verbose appending log.
  --proxy              Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries          Maximum number of retries each connection should attempt (default 5 times).
  --timeout              Set the socket timeout (default 15 seconds).
  --exists-action     Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).
  --trusted-host    Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert                Path to alternate CA bundle.
  --client-cert         Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  --cache-dir            Store the cache data in .
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
  --no-color                  Suppress colored output

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>
C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>
C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>pip3 install numpy
Collecting numpy
  Using cached https://files.pythonhosted.org/packages/20/ed/e036d31a9b2c750f270cbb1cfc1c0f94ac78ae504eea7eec3267be4e294a/numpy-1.16.4-cp36-cp36m-win_amd64.whl
Installing collected packages: numpy
Successfully installed numpy-1.16.4
You are using pip version 18.1, however version 19.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>

(7)升级pip3(系统中已经存在pyhton2和pip2)

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>python36 -m pip install --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
      Successfully uninstalled pip-18.1
Successfully installed pip-19.1.1

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>pip -V
pip 19.1.1 from c:\python27\lib\site-packages\pip (python 2.7)

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>pip3 -V
pip 19.1.1 from c:\caffe_draft\thirdparty\python-3.6.8\python-3.6.8\lib\site-packages\pip (python 3.6)

C:\caffe_draft\thirdparty\Python-3.6.8\Python-3.6.8\PCbuild\amd64>

Win10+VS2015+python3.6.8源码编译安装_第3张图片

 

(8)Pycharm中使用python3.6.8

Win10+VS2015+python3.6.8源码编译安装_第4张图片

 

Win10+VS2015+python3.6.8源码编译安装_第5张图片

 

 

(9)设置pip下载路径,安装常用python依赖包

Win10+VS2015+python3.6.8源码编译安装_第6张图片

 

pip freeze > requirements.txt

pip3 install -r requirements.txt

使用国内pip源,这里使用清华大学

pip3 install XXX -i https://pypi.tuna.tsinghua.edu.cn/simple/

pip3 install -r C:\caffe_happynear\caffe-windows-ms\python\requirements.txt  -i https://pypi.tuna.tsinghua.edu.cn/simple

leveldb无法用pip安装,用#注释掉,leveldb数据库可以用lmdb代替。

提示不兼容,python-dateutil>=1.4,<2导致python-dateutil版本太低,matplot和pandas需要其版本大于2.5

由于这里是自己山寨caffe,不是编译caffe,可以没有这个限制。修改requirements.txt如下,重新安装

Cython>=0.19.2
numpy>=1.7.1
scipy>=0.13.2
scikit-image>=0.9.3
matplotlib>=1.3.1
ipython>=3.0.0
h5py>=2.2.0
#leveldb>=0.191
networkx>=1.8.1
nose>=1.3.0
pandas>=0.12.0
#python-dateutil>=1.4,<2
python-dateutil>=2.5
protobuf>=2.5.0
python-gflags>=2.0
pyyaml>=3.10
Pillow>=2.3.0
six>=1.1.0

 

(10)编译Debug版本

Win10+VS2015+python3.6.8源码编译安装_第7张图片

 

 

 

 

你可能感兴趣的:(Python零基础)