# https://portablepython.com/
# https://portablepython.com/wiki/Download/
還好有一位專家 Aman Ansari 繼續封裝 v3.7.0, 可從 Source Forge 下載 :
# https://sourceforge.net/projects/portable-python/
此為 64 位元版, 下載的 zip 檔大約 32MB, 解開後約 110MB, 可放在隨身碟中執行, 其目錄結構如下 :
其中有四個開啟程式 (Launcher) :
- Python_Launcher.exe : 開啟命令提示字元視窗執行 Python.exe
- IDLE-Launcher.exe : 開啟 IDLE 介面
- PyScripter-Launcher.exe : 開啟 PyScripter 編輯器
- Console-Launcher.exe : 開啟命令提示字元視窗
- python -m pip install package_name (安裝套件模組)
- python -m pip install --upgrade pip (升版 pip)
- python -m pip list (檢視已安裝套件模組)
- python -m pip uninstall package_name (移除套件模組)
- python -m pip list --outdated (顯示過時套件模組)
- python -m pip search "package_name" (搜尋套件模組)
Microsoft Windows [版本 10.0.17134.345]
(c) 2018 Microsoft Corporation. 著作權所有,並保留一切權利。
D:\PortablePython37<python -m pip list
Package Version
---------- -------
pip 10.0.1
setuptools 39.0.1
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
可見預設只安裝了 pip 與 setuptools 這兩個模組而已, 在網路暢通環境下可用 python -m pip install 指令安裝所需要的模組. 但在離線或有防火牆阻擋環境下, 則需要用到 App\Python\Scripts 下的 setup_tools.exe 安裝已下載的模組檔案 (whl 或 gz 檔) :
# 如何在 Portable Python 離線安裝模組
不過由於模組相依問題, 離線安裝通常要準備全部相依的模組才能順利安裝, 作者建議在網路暢通環境下安裝全部用得到的模組較省事. 我常用的模組安裝指令如下, 主要是機器學習與網路爬蟲等相關之模組 :
python -m pip install scipy
python -m pip install pandas
python -m pip install matplotlib
python -m pip install scikit-learn
python -m pip install --upgrade tensorflow
python -m pip install keras
python -m pip install requests
python -m pip install beautifulsoup4
python -m pip install lxml
python -m pip install html5lib
python -m pip install selenium
python -m pip install pymysql
python -m pip install mysqlclient
python -m pip install xlrd
python -m pip install fix_yahoo_finance
python -m pip install openpyxl
python -m pip install "django<1.9"
python -m pip install virtualenv
python -m pip install paramiko
注意 :
如果電腦中原本已安裝了 Python, 則必須到 "系統/進階設定" 中將 path 中的 Python 路徑 (例如 C:\Python36\Scripts\, C:\Python36\) 暫時移除, 否則 pip install 安裝時會安裝到原本的 Python 安裝目錄裡, 而不是 Portable Python 裡, 安裝完再恢復 path 原設定. 另外, Numpy 於安裝 Scipy 時會一併安裝, 不需單獨安裝.
不過由於模組相依問題, 離線安裝通常要準備全部相依的模組才能順利安裝, 作者建議在網路暢通環境下安裝全部用得到的模組較省事. 我常用的模組安裝指令如下, 主要是機器學習與網路爬蟲等相關之模組 :
python -m pip install scipy
python -m pip install pandas
python -m pip install matplotlib
python -m pip install scikit-learn
python -m pip install requests
python -m pip install beautifulsoup4
python -m pip install lxml
python -m pip install html5lib
python -m pip install selenium
python -m pip install pymysql
python -m pip install mysqlclient
python -m pip install xlrd
python -m pip install fix_yahoo_finance
python -m pip install openpyxl
python -m pip install "django<1.9"
python -m pip install virtualenv
python -m pip install paramiko
注意 :
如果電腦中原本已安裝了 Python, 則必須到 "系統/進階設定" 中將 path 中的 Python 路徑 (例如 C:\Python36\Scripts\, C:\Python36\) 暫時移除, 否則 pip install 安裝時會安裝到原本的 Python 安裝目錄裡, 而不是 Portable Python 裡, 安裝完再恢復 path 原設定. 另外, Numpy 於安裝 Scipy 時會一併安裝, 不需單獨安裝.
上面的模組除了 mysqlclient 外均順利安裝完成, mysqlclient 則出現如下錯誤訊息 :
D:\PortablePython37>python -m pip install mysqlclient
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
Complete output from command D:\PortablePython37\App\Python\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\TONYHU~1\\AppData\\Local\\Temp\\pip-install-0cfu1z52\\mysqlclient\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\TONYHU~1\AppData\Local\Temp\pip-record-tzrl7s3z\install-record.txt --single-version-externally-managed --compile:
D:\PortablePython37\App\Python\lib\distutils\dist.py:274: UserWarning: Unknown distribution option: 'long_description_content_type'
warnings.warn(msg)
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.7
copying _mysql_exceptions.py -> build\lib.win-amd64-3.7
creating build\lib.win-amd64-3.7\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win-amd64-3.7\MySQLdb
copying MySQLdb\compat.py -> build\lib.win-amd64-3.7\MySQLdb
copying MySQLdb\connections.py -> build\lib.win-amd64-3.7\MySQLdb
copying MySQLdb\converters.py -> build\lib.win-amd64-3.7\MySQLdb
copying MySQLdb\cursors.py -> build\lib.win-amd64-3.7\MySQLdb
copying MySQLdb\release.py -> build\lib.win-amd64-3.7\MySQLdb
copying MySQLdb\times.py -> build\lib.win-amd64-3.7\MySQLdb
creating build\lib.win-amd64-3.7\MySQLdb\constants
copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.7\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.7\MySQLdb\constants
copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.7\MySQLdb\constants
copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.7\MySQLdb\constants
copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.7\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.7\MySQLdb\constants
copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.7\MySQLdb\constants
running build_ext
building '_mysql' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
----------------------------------------
Command "D:\PortablePython37\App\Python\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\TONYHU~1\\AppData\\Local\\Temp\\pip-install-0cfu1z52\\mysqlclient\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\TONYHU~1\AppData\Local\Temp\pip-record-tzrl7s3z\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\TONYHU~1\AppData\Local\Temp\pip-install-0cfu1z52\mysqlclient\
有看沒有懂, 這模組就算了, 反正有 PyMySQL 就可以了.
另外, 因 tensorflow 目前僅支援到 Python 3.6, 而此 Portable Python 為 3.7.0 版, 因此用 pip 安裝時會報 "No matching distribution found" 錯誤, 所以就先不安裝, 等以後支援了再說, 連帶 Keras 也是以後再安裝 :
D:\PortablePython37>python -m pip install tensorflow
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
最後用 pip list 查看已安裝模組如下 :
另外, 因 tensorflow 目前僅支援到 Python 3.6, 而此 Portable Python 為 3.7.0 版, 因此用 pip 安裝時會報 "No matching distribution found" 錯誤, 所以就先不安裝, 等以後支援了再說, 連帶 Keras 也是以後再安裝 :
D:\PortablePython37>python -m pip install tensorflow
Collecting tensorflow
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
最後用 pip list 查看已安裝模組如下 :
D:\PortablePython37>python -m pip list
Package Version
----------------- ----------
asn1crypto 0.24.0
bcrypt 3.1.4
beautifulsoup4 4.6.3
certifi 2018.10.15
cffi 1.11.5
chardet 3.0.4
cryptography 2.3.1
cycler 0.10.0
Django 1.8.19
et-xmlfile 1.0.1
fix-yahoo-finance 0.0.22
html5lib 1.0.1
idna 2.7
jdcal 1.4
kiwisolver 1.0.1
lxml 4.2.5
matplotlib 3.0.0
multitasking 0.0.7
numpy 1.15.3
openpyxl 2.5.9
pandas 0.23.4
paramiko 2.4.2
pip 18.1
pyasn1 0.4.4
pycparser 2.19
PyMySQL 0.9.2
PyNaCl 1.3.0
pyparsing 2.2.2
python-dateutil 2.7.3
pytz 2018.6
requests 2.20.0
scikit-learn 0.20.0
scipy 1.1.0
selenium 3.14.1
setuptools 39.0.1
six 1.11.0
urllib3 1.24
webencodings 0.5.1
xlrd 1.1.0
安裝完後約 350MB, 沒想到這些模組加起來竟然這麼大! 重新壓縮後的 ZIP 檔也膨脹到 150MB 左右, 這樣就可以移到無法線上安裝的電腦使用了.
2018-10-26 補充 :
安裝完所需模組移到網內使用時若仍發現缺了那些模組, 不用回網外電腦安裝後再搬檔案, 只要去 PyPi 網站下載該模組之 whl 檔 (以及所有相依模組) 安裝即可, 例如今天發現 pexpect 好用沒安裝到, 於是下載了 pexpect 及其相依模組 ptyprocess 以 pip 安裝m 例如 :
C:\Python37>python -m pip install ptyprocess-0.6.0-py2.py3-none-any.whl
Processing c:\python37\ptyprocess-0.6.0-py2.py3-none-any.whl
Installing collected packages: ptyprocess
Successfully installed ptyprocess-0.6.0
C:\Python37>python -m pip install pexpect-4.6.0-py2.py3-none-any.whl
Processing c:\python37\pexpect-4.6.0-py2.py3-none-any.whl
Requirement already satisfied: ptyprocess>=0.5 in c:\python37\app\python\lib\sit
e-packages (from pexpect==4.6.0) (0.6.0)
Installing collected packages: pexpect
Successfully installed pexpect-4.6.0
Processing c:\python37\pexpect-4.6.0-py2.py3-none-any.whl
Requirement already satisfied: ptyprocess>=0.5 in c:\python37\app\python\lib\sit
e-packages (from pexpect==4.6.0) (0.6.0)
Installing collected packages: pexpect
Successfully installed pexpect-4.6.0
沒有留言:
張貼留言