Python 3.x标准模块库以及常用依赖安装

一、常用链接:

https://blog.csdn.net/sadfishsc/article/details/10390065

Unofficial Windows Binaries for Python Extension Packages:
https://www.lfd.uci.edu/~gohlke/pythonlibs/

二、库的安装

比如:pygame
(建议安装Anaconda,而不仅仅是安装Python环境)
如果安装了Anacaonda则自带PIP工具(如果没有安装PIP则通过链接去下载安装:https://pypi.python.org/pypi/pip#downloads,在cmd里cd到这个解压目录,输入python setup.py install即可完成PIP的安装)
1、下载whl文件(https://www.lfd.uci.edu/~gohlke/pythonlibs/中寻找)
pygame-1.9.4-cp37-cp37m-win_amd64.whl

2、在下载文件目录中执行:(中间会遇到各种问题)

C:\MySoftwares\Python-whl>pip install pygame-1.9.4-cp37-cp37m-win_amd64.whl

pygame-1.9.4-cp37-cp37m-win_amd64.whl is not a supported wheel on this platform.
You are using pip version 9.0.1, however version 19.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

(1)如遇上面的提示,则是由于版本不匹配造成的,需要升级PIP:

>python -m -pip install --upgrade pip


Collecting pip
  Downloading https://files.pythonhosted.org/packages/d7/41/34dd96bd33958e52cb4da2f1bf0818e396514fd4f4725a79199564cd0c20/pip-19.0.2-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 79kB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Uninstalling pip-9.0.1:
      Successfully uninstalled pip-9.0.1
Successfully installed pip-19.0.2

升级成功后,则再执行安装whl:

C:\MySoftwares\Python-whl>pip install pygame-1.9.4-cp37-cp37m-win_amd64.whl

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Processing c:\mysoftwares\python-whl\pygame-1.9.4-cp37-cp37m-win_amd64.whl
Installing collected packages: pygame
Successfully installed pygame-1.9.4
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

(2)如遇上面的提示,则是由于需要的依赖openssl-devel没有安装:
两种安装方式:直接下载安装包安装;编译源码安装;

要想安装openssl-devel则需要安装perl(草莓版即可)和VS插件
Strawberry版本的perl,下载安装即可:https://www.perl.org/get.html
此种方法比较麻烦,如果是在Linux环境下可以一键搞定,但是在Windows环境下就很麻烦了。
可以参考:https://www.cnblogs.com/lpxblog/p/5382653.html

推荐采取直接安装的方式:http://slproweb.com/products/Win32OpenSSL.html下载对应版本。

安装完后:

C:\MySoftwares\Python-whl>pip install pygame-1.9.4-cp37-cp37m-win_amd64.whl

Requirement already satisfied: pygame==1.9.4 from file:///C:/MySoftwares/Python-whl/pygame-1.9.4-cp37-cp37m-win_amd64.whl in c:\mysoftwares\anaconda3\lib\site-packages (1.9.4)

验证是否安装成功:

C:\MySoftwares\Python-whl>python
Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
>>>

成功!!

三、Python程序的打包

1、如何将程序打成可执行的文件(.exe)
(1)安装Pyinstaller
首先要安装pywin32
下载安装文件:查找到跟自己适用的python版本及window系统版本匹配的pywin32,下载后安装 :https://pypi.org/project/pywin32/#files
比如我下载的是:pywin32-224-cp37-cp37m-win_amd64.whl
使用pip命令安装:pip install pywin32-224-cp37-cp37m-win_amd64.whl

C:\MySoftwares\Python-whl>pip install pywin32-224-cp37-cp37m-win_amd64.whl
Processing c:\mysoftwares\python-whl\pywin32-224-cp37-cp37m-win_amd64.whl
Installing collected packages: pywin32
  Found existing installation: pywin32 223
    Uninstalling pywin32-223:
      Successfully uninstalled pywin32-223
Successfully installed pywin32-224

然后,再安装Pyinstaller(https://pypi.org/project/PyInstaller/#files),需要注意的是,一定要选择合适的版本,否则一定安装不成功

版本不匹配:
setup.py is not yet supposed to work. Please Use PyInstaller without installation.

我下载的是:PyInstaller 3.4,解压PyInstaller-3.4.tar.gz,在解压目录下执行:

>python setup.py install
C:\MySoftwares\Python-whl\dist\PyInstaller-3.4>python setup.py install
running install
running bdist_egg
running build_bootloader
running egg_info
writing PyInstaller.egg-info\PKG-INFO
……
……
……
……
……
……
Installing macho_find.exe script to C:\MySoftwares\anaconda3\Scripts
Installing macho_standalone-script.py script to C:\MySoftwares\anaconda3\Scripts
Installing macho_standalone.exe script to C:\MySoftwares\anaconda3\Scripts

Installed c:\mysoftwares\anaconda3\lib\site-packages\macholib-1.11-py3.7.egg
Searching for pefile>=2017.8.1
Reading https://pypi.org/simple/pefile/
Downloading https://files.pythonhosted.org/packages/ed/cc/157f20038a80b6a9988abc06c11a4959be8305a0d33b6d21a134127092d4/pefile-2018.8.8.tar.gz#sha256=4c5b7e2de0c8cb6c504592167acf83115cbbde01fe4a507c16a1422850e86cd6
Best match: pefile 2018.8.8
Processing pefile-2018.8.8.tar.gz
Writing C:\Users\Xuekao.HU\AppData\Local\Temp\easy_install-0x3rpy02\pefile-2018.8.8\setup.cfg
Running pefile-2018.8.8\setup.py -q bdist_egg --dist-dir C:\Users\Xuekao.HU\AppData\Local\Temp\easy_install-0x3rpy02\pefile-2018.8.8\egg-dist-tmp-vi6ueufl
warning: no previously-included files found matching 'run_tests.py'
warning: no previously-included files found matching 'requirements.txt'
warning: no previously-included files found matching 'README.md'
no previously-included directories found matching 'tests'
zip_safe flag not set; analyzing archive contents...
Copying pefile-2018.8.8-py3.7.egg to c:\mysoftwares\anaconda3\lib\site-packages
Adding pefile 2018.8.8 to easy-install.pth file

Installed c:\mysoftwares\anaconda3\lib\site-packages\pefile-2018.8.8-py3.7.egg
Searching for setuptools==40.6.3
Best match: setuptools 40.6.3
Adding setuptools 40.6.3 to easy-install.pth file
Installing easy_install-script.py script to C:\MySoftwares\anaconda3\Scripts
Installing easy_install.exe script to C:\MySoftwares\anaconda3\Scripts

Using c:\mysoftwares\anaconda3\lib\site-packages
Searching for future==0.17.1
Best match: future 0.17.1
Adding future 0.17.1 to easy-install.pth file
Installing futurize-script.py script to C:\MySoftwares\anaconda3\Scripts
Installing futurize.exe script to C:\MySoftwares\anaconda3\Scripts
Installing pasteurize-script.py script to C:\MySoftwares\anaconda3\Scripts
Installing pasteurize.exe script to C:\MySoftwares\anaconda3\Scripts

Using c:\mysoftwares\anaconda3\lib\site-packages
Finished processing dependencies for PyInstaller==3.4

最后定位到要打包的py文件目录执行:

>pyinstaller -F myfile.py

即可。

2、更推荐的方式是利用IDE进行打包:(Pycharm)
在Pycharm的“Terminal”窗口中,执行:pip install pyinstaller,再执行:pyinstaller -F -w myFile.py

注意:
如果出现:

Original error was: DLL load failed: 找不到指定的模块。

则最好进行更新:

C:\Users\Xuekao.HU>conda upgrade numpy
Solving environment: done

## Package Plan ##

  environment location: C:\MySoftwares\anaconda3

  added / updated specs:
    - numpy


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    conda-4.6.3                |           py37_0         1.7 MB

The following packages will be UPDATED:

    conda: 4.5.12-py37_0 --> 4.6.3-py37_0

Proceed ([y]/n)? y


Downloading and Extracting Packages
conda-4.6.3          | 1.7 MB    | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

你可能感兴趣的:(Python)