The module pymysintall proposes an easy to install module mostly on Windows as it is already quite easy to do it on Linux/Mac through pip. There are a couple of ways to install a module and they should be tried in that way:
Old way which should not be used anymore:
pip is great because it deals with dependencies for you. I recommend to use Pyhon 3.4 because that is the first version which includes pip
. It takes the modules from PyPI. The only drawback happens on Windows when a module includes Fortran/C/C++ files which must be compiled. As opposed to Linux or Mac with gcc, there is not an official compiler to handle every package and it has to be installed first. On Windows, it can be done by installing Visual Studio Express 2010 but sometimes, the dependencies can be tricky. That's why it is recommended to install already compiled python extensions. Not every module provides a compiled version but there exists two main ways to get them:
pymysintall takes the setup from the first source. The following snippets of code gives an example for each described way to install a module. The setup way only works on Windows.
pip
Let's try with the following module: numbers_extractor.
from pymyinstall import ModuleInstall
ModuleInstall("numbers_extractor", "pip").install()
wheel (for files *.whl)
ModuleInstall("numpy", "wheel").install()
The function checks first if the module was already installed. That explains why a second run does not print anything.
ModuleInstall("numbers_extractor", "pip").install()
exe
We try with the module snappy.
ModuleInstall("python-snappy", "exe", mname="snappy").install()
Here again a second call does not do anything. python-snappy
is the prefix of the setup, snappy
is its name when we need to import it: import snappy
.
ModuleInstall("python-snappy", "exe", mname="snappy").install()
Unfortunately, some modules are missing from Unofficial Windows Binaries for Python Extension Packages such as paramiko which I use to open a SSH connection. For this one, exe
must be replaced by exe_xd
. This way only works in Windows but not on Linux or Mac.
github
github holds the source of most of the open source project. This one is no exception. You can check this page for example Top 400 Python Projects in Github. We try here with the module bottle <https://github.com/defnull/bottle>
_.
ModuleInstall("bottle", "github", "defnull").install()
The function downloads the source from GitHub and install them using the instruction python setup.py install
. The function still has to be improved because analyzing the output is always obvious if there are dependencies or error messages. We check again a second call does not install the module again.
ModuleInstall("bottle", "github", "defnull").install()
We finally check the module can be imported. It sometimes requires the kernel to restarted.
import bottle
The two previous methods download files and create others when some file needs to be uncompressed.
import os
os.listdir(".")