[PYTHON] Mastering pip and wheel on windows

The environment created in this post can be built with https://bitbucket.org/toruuetani/venv_base. Running hg clone and running cmd.bat builds a virtualenv environment with Fabric installed.

Premise

It is another windows PC that develops on a windows PC and runs it. However, the PC works in an offline environment.

Why start using pip nowadays

Because pip cannot be installed from binary. Non-pure python packages have to be compiled from source, but unlike linux, windows often doesn't have a C compiler, so you can't install them. Therefore, a binary package is available for windows (such as XXX-1.2.1.win32-py2.7.exe). This binary package works fine with easy_install, but not with pip. So no matter how much pip evolved, it was easy_install for windows.

The above situation has been improved with the advent of the wheel. The wheel format also includes binaries, so with the exception of special packages (pywin32, psycopg2, py2exe, etc.), you can do it with just pip.

2014/02/14 postscript -> Here, but wininst2wheel makes it easier to migrate from easy_install to pip.

Building a modern environment

I can't think of an environment that doesn't use virtualenv at the moment, so I'll use it.

The following directories are used in the following explanations.

Building a virtualenv environment

If you download virtualenv-1.11.2.tar.gz from https://pypi.python.org/pypi/virtualenv/ and unzip it, the following file will be created, so use this.

python virtualenv.py %VENV_DIR%

Now you can use easy_install and pip.

wheel installation

Download and use wheel-0.22.0.tar.gz from https://pypi.python.org/pypi/wheel/.

pip install wheel-0.22.0.tar.gz

Now you can use the wheel format.

How to make a wheel

By convention, wheels are stored in a directory called wheelhouse, so follow this.

pip wheel %PACKAGE_NAME% -w "%WHEELHOUSE_DIR%"

For example, to create a wheel of Fabric, do as follows.

pip wheel Fabric -w "%WHEELHOUSE_DIR%"

It will resolve the dependencies and create a wheel for you.

(Note) There is a bug in pip at the moment, so it will not be created if it is registered in PyPI. Therefore, only Fabric-1.8.1-py2.py3-none-any.whl is downloaded from PyPI.

Installation using wheel

pip wheel only creates a wheel, so to actually install it using pip install

pip install "%WHEELHOUSE_DIR%\Fabric-1.8.1-py2.py3-none-any.whl"

To do. If you do pip freeze in this state, the currently installed packages will be displayed.

> pip freeze
Fabric==1.8.1
ecdsa==0.10
paramiko==1.12.1
pycrypto==2.6.1
wheel==0.22.0

pip has a mechanism to install packages based on the result of pip freeze. If you save the above result as requirements.txt, you can install the packages at once. Since the wheel has already been created and there is no need to search for PyPI, add --no-index. If you have a certain number of packages, this method will be convenient.

pip install -r requirements.txt -f "%WHEELHOUSE_DIR%" --no-index

Summary

If you have a wheel stored in a wheelhouse, you can build an environment even in an offline environment. At the moment, I still have to rely on easy_install for some, but it's practical enough.

Recommended Posts

Mastering pip and wheel on windows
Install easy_install and pip on windows
[Python] pip and wheel
Use pip on Windows
Notes on installing Python3 and using pip on Windows7
Install ZIP version Python and pip on Windows 10
Python 3.6 on Windows ... and to Xamarin.
Install Python on Windows + pip + virtualenv
Build and install OpenCV on Windows
Integrate Modelica and Python on Windows
[UE4] Build DedicatedServer on Windows and Linux
Run py.test on Windows Anaconda and MinGW
Put MeCab binding for Python with pip on Windows, mac and Linux
Install and run Python3.5 + NumPy + SciPy on Windows 10
(Windows) Causes and workarounds for UnicodeEncodeError on Python 3
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
[Note] Installing Python 3.6 + α on Windows and RHEL
Eliminates SSL error when PIP Install on Windows.
Initial settings for using Python3.8 and pip on CentOS8
Install pip on Mavericks
Pylint on Windows Atom
Linux (WSL) on Windows
Use pyvenv on Windows
Anaconda on Windows Terminal
[Windows] [Python3] Install python3 and Jupyter Notebook (formerly ipython notebook) on Windows
Install Anaconda on Windows 10
python basic on windows ②
Install python on windows
Install pycuda on Windows10
Build TensorFlow on Windows
Try FEniCS on Windows!
Build XGBoost on Windows
Install pygraphviz on Windows 10
Use Ansible on Windows
Try Poerty on Windows
Dealing with pip and related installation errors on Ubuntu 18.04
Install Chainer 1.5.0 on Windows
Use QuTiP on Windows
Create a decent shell and python environment on Windows
Install pip / pip3 on Ubuntu
Until you create Python Virtualenv on Windows and launch Jupyter
Install python3 and scientific calculation library on Ubuntu (virtualenv + pip)
Install Jupiter Notebook on Windows with pip in proxy environment
Install python and Visual Studio Code on windows10 (April 2020 version)
Python and pip commands are not available on CentOS (RHEL) 8
Install Numpy on virtualenv on Windows
Set-enable Python virtualenv on Windows
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
Notes on tf.function and Tracing
Python on Ruby and angry Ruby on Python
Install Python and Flask (Windows 10)
Before trying Veriloggen on Windows
Notes on * args and ** kargs
Install cvxpy on windows, Anaconda
Python + Kivy development on Windows
Try using OpenCV on Windows
F2py on Miniconda for Windows
Recording and playback on Linux
Notes on pyenv and Atom
Sphinx-autobuild (0.5.2) on Windows7, Python 3.5.1, Sphinx 1.3.5