If there is anything I like about Windows as a pythonist, it must be that you can use embedded distribution of python.
The embedded distribution is a ZIP file containing a minimal Python environment. It is intended for acting as part of another application, rather than being directly accessed by end-users.
In my opinion, it is a portable, ready-to-ship virtualenv. However, the embedded distribution comes with some limitation:
Third-party packages should be installed by the application installer alongside the embedded distribution. Using pip to manage dependencies as for a regular Python installation is not supported with this distribution, though with some care it may be possible to include and use pip for automatic updates. In general, third-party packages should be treated as part of the application (“vendoring”) so that the developer can ensure compatibility with newer versions before providing updates to users.
Sounds scary right? It said it doesn't even support pip. Don't worry, followthese simple steps, you will have a fully workable embedded environment.
- Go to https://www.python.org/downloads/windows/
- Choose the version python you like and download the corresponding
Windows x86-64 embeddable zip file.
- Unzip the file.
To make this tutorial easy to follow, I am assuming that you have downloaded
Python3.7 and unzipped it to
The distribution does not have pip installed in place, you need to install it yourself:1. Download
get-pip.py at https://bootstrap.pypa.io/get-pip.py2. Save it to
c:\python\get-pip.py3. In command-line run
C:\python\python get-pip.py4. pip is now installed
The runtime of this distribution doesn't have an empty string
'' added in
sys.path,so that the
current directory is not added into
sys.path, to solve the problem,you need to:
- Uncomment the line
#import siteand save.
- Create a new .py file and save it as
import sys sys.path.insert(0, '')
You will encounter the following error when you try to install some packages:
error: [Errno 0] Error: 'lib2to3\\Grammar3.6.5.final.0.pickle'
- Rename the
python37.zip(yes, a new folder called
Python's import module is able to treat zip file as folder however, it cannot read pickle file inside a zip file, so unzip it and rename it.
If you don't want to mess with you PATH, you can simply do the following in your window command prompt:
pip install xxxxx
Again if you don't want to mess with you PATH, you can simply do in your window command prompt:
C:\python\python <path to your script>