error: Unable to find vcvarsall.bat when compiling Cython code
I spent hours on this, and the information was not easily findable in error: Unable to find vcvarsall.bat, that's why I post it here with the "answer your own question" feature:
Step 1: Install Microsoft Visual C++ Compiler for Python 2.7
Remark: You don't need to modify
msvc9compiler.py
as often suggested in many forum postsStep 2: Just add
import setuptools
that will help Python and "Microsoft Visual C++ Compiler for Python 2.7" work together.import setuptools # important
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize("module1.pyx", build_dir="build"),
script_args=['build'],
options={'build':{'build_lib':'.'}})Note: the
script_args
parameter allows to run this setup.py with justpython setup.py
(i.e. CTRL+B in your favorite editor like Sublime Text) instead of having to pass command-line arguments like this:python setup.py build
.
It works!
Python Pip install Error: Unable to find vcvarsall.bat. Tried all solutions
I have tried all suggestions and found my own simple solution.
The problem is that codes written in external environment like C
need compiler. Look for its own VS environment, i.e. VS 2008.
Currently my machine runs VS 2012 and faces Unable to find vcvarsall.bat
.
I studied codes that i want to install to find the VS version. It was VS 2008. i have add to system variable VS90COMNTOOLS
as variable name and gave the value of VS120COMNTOOLS
.
You can find my step by step solution below:
- Right click on My Computer.
- Click Properties
- Advanced system settings
- Environment variables
- Add New system variable
- Enter VS90COMNTOOLS to the variable name
- Enter the value of current version to the new variable.
- Close all windows
Now open a new session and pip install your-package
unable to find vcvarsall.bat error
This is a well-known problem with installing the lxml Python library on Windows.
The TL;DR version here is you install lxml
from a "binary installation package" which comes pre-compiled and takes care of all the details for you.
You can find one of those here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
The 'cp' segment stands for 'C Python' (regular Python, as opposed to PyPy for example) and the version, so if you're using Python 2.7 you want one of the packages with -cp27-
in the name. There are two of these, one for 32-bit and one for 64-bit. You probably want 32-bit because that's the default Python install on Windows.
Once you download the binary installation package ("wheel"), you install it using pip
, e.g.:
pip install lxml‑3.6.4‑cp27‑cp27m‑win32.whl
pip install gives error: Unable to find vcvarsall.bat
You could use ol' good easy_install zipline
instead.
easy_install
isn't pip but one good aspect of it is the ability to download and install binary packages too, which would free you for the need having VC++ ready. This of course relies of the assumption that the binaries were prepared for your Python version.
UPDATE:
Yes, Pip can install binaries now!
There's a new binary Python archive format (wheel) that is supposed to replace "eggs". Wheels are already supported by pip
. This means you'll be able to install zipline
with pip
without compiling it as soon as someone builds the wheel for your platform and uploads it to PyPI.
Related Topics
Python Spawn Off a Child Subprocess, Detach, and Exit
Run Multiple Python Scripts Concurrently
How to Terminate Process from Python Using Pid
Python Subprocess.Popen "Oserror: [Errno 12] Cannot Allocate Memory"
How to Set Your Pythonpath in an Already-Created Virtualenv
Process List on Linux Via Python
Python-Dev Installation Error: Importerror: No Module Named Apt_Pkg
Cannot Kill Python Script With Ctrl-C
Django [Errno 13] Permission Denied: '/Var/Www/Media/Animals/User_Uploads'
Tkinter.Photoimage Doesn't Not Support Png Image
Cross-Platform Space Remaining on Volume Using Python
Force Python to Use an Older Version of Module (Than What I Have Installed Now)
How to Update a Python Package
How to Listen For 'Usb Device Inserted' Events in Linux, in Python
How Would I Build Python Myself from Source Code on Ubuntu
Why Can a Function Modify Some Arguments as Perceived by the Caller, But Not Others